File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 22
22
},
23
23
install_requires = [
24
24
'pytest >= 2.8' ,
25
+ 'pytest-mock' ,
25
26
'jupyter_client' ,
26
27
'nbformat' ,
27
28
'ipykernel' ,
Original file line number Diff line number Diff line change
1
+
2
+ from utils import build_nb , add_expected_plaintext_outputs
3
+
4
+ import nbdime
5
+ import nbformat
6
+ import os
7
+
8
+
9
+ def test_nbdime (testdir , mocker ):
10
+
11
+ # Make a test notebook where output doesn't match input
12
+ nb = build_nb (["1+1" , "1+1" ], mark_run = True )
13
+ add_expected_plaintext_outputs (nb , ["2" , "3" ])
14
+ # Write notebook to test dir
15
+ filename = 'test_nbdime.ipynb'
16
+ nbformat .write (nb , os .path .join (str (testdir .tmpdir ), filename ))
17
+
18
+ # patch the run_server function so that it doesn't actually
19
+ # spawn a server and display the diff. But the diff is still
20
+ # calculated.
21
+ mocker .patch ('nbdime.webapp.nbdiffweb.run_server' )
22
+ result = testdir .runpytest_inprocess ('--nbval' ,
23
+ '--nbval-current-env' ,
24
+ '--nbdime' ,
25
+ filename )
26
+ # run_server() is only called if there is a discrepancy in the notebook.
27
+ # so it should have been called in this case:
28
+ nbdime .webapp .nbdiffweb .run_server .assert_called_once ()
29
+
30
+ # note: this import must be AFTER the mocker.patch
31
+ from nbval .nbdime_reporter import EXIT_TESTSFAILED
32
+ assert result .ret == EXIT_TESTSFAILED
You can’t perform that action at this time.
0 commit comments