1+ import os
12from pathlib import Path
23
3- from _pytest .pytester import Testdir
44from nbformat import write
55from nbformat .v4 import new_code_cell , new_notebook , new_output
6+ from pytest import Pytester
7+ from typing_extensions import Never
68
79NB_VERSION = 4
810from nbmake .nb_result import NotebookResult
1618
1719
1820class TestNotebookRun :
19- def test_when_passing_then_no_failing_cell (self , testdir2 : Testdir ):
21+ def test_when_passing_then_no_failing_cell (self , testdir2 : Never ):
2022 write_nb (passing_nb , filename )
2123
2224 run = NotebookRun (filename , 300 )
2325 res : NotebookResult = run .execute ()
2426
2527 assert res .error == None
2628
27- def test_when_runs_then_cwd_is_nb_location (self , testdir2 : Testdir ):
29+ def test_when_runs_then_cwd_is_nb_location (self , testdir2 : Never ):
2830 subdir = Path ("subdir" )
29- subdir .mkdir ()
31+ subdir .mkdir (exist_ok = True )
3032 write_nb (
3133 ["import os; assert os.getcwd().endswith('subdir')" ], subdir / filename
3234 )
@@ -36,14 +38,14 @@ def test_when_runs_then_cwd_is_nb_location(self, testdir2: Testdir):
3638
3739 assert res .error == None
3840
39- def test_failing (self , testdir2 : Testdir ):
41+ def test_failing (self , testdir2 : Never ):
4042 write_nb (failing_nb , filename )
4143 run = NotebookRun (filename , 300 )
4244 res : NotebookResult = run .execute ()
4345
4446 assert res .error and res .error .failing_cell_index == 1
4547
46- def test_when_allow_errors_then_passing (self , testdir2 : Testdir ):
48+ def test_when_allow_errors_then_passing (self , testdir2 : Never ):
4749 nb = new_notebook ()
4850 nb .metadata .execution = {"allow_errors" : True }
4951 cell = new_code_cell ("raise Exception()" )
@@ -56,7 +58,7 @@ def test_when_allow_errors_then_passing(self, testdir2: Testdir):
5658 assert not res .error
5759 assert res .nb .cells [0 ].outputs [0 ].ename == "Exception"
5860
59- def test_when_timeout_then_fails (self , testdir2 : Testdir ):
61+ def test_when_timeout_then_fails (self , testdir2 : Never ):
6062 nb = new_notebook ()
6163 nb .metadata .execution = {"timeout" : 1 }
6264 nb .cells += [
@@ -72,7 +74,7 @@ def test_when_timeout_then_fails(self, testdir2: Testdir):
7274 assert not Path ("fail.txt" ).exists ()
7375 assert res .error and res .error .failing_cell_index == 1
7476
75- def test_when_executed_then_stripped_out (self , testdir2 : Testdir ):
77+ def test_when_executed_then_stripped_out (self , testdir2 : Never ):
7678 nb = new_notebook (metadata = {})
7779 nb .cells += [
7880 new_code_cell (
@@ -91,7 +93,7 @@ def test_when_executed_then_stripped_out(self, testdir2: Testdir):
9193 assert res .nb .cells [0 ].outputs [0 ].ename == "Exception"
9294 assert res .nb .cells [1 ].outputs == []
9395
94- def test_when_unknown_kernel_then_error (self , testdir2 : Testdir ):
96+ def test_when_unknown_kernel_then_error (self , testdir2 : Never ):
9597 nb = new_notebook (
9698 metadata = {"kernelspec" : {"display_name" : "asdf" , "name" : "asdf" }}
9799 )
@@ -102,19 +104,19 @@ def test_when_unknown_kernel_then_error(self, testdir2: Testdir):
102104 res : NotebookResult = run .execute ()
103105 assert res .error and "No such kernel" in res .error .summary
104106
105- def test_when_cell_ignored_then_does_not_run (self , testdir2 : Testdir ):
107+ def test_when_cell_ignored_then_does_not_run (self , testdir2 : Never ):
106108 nb = Path (__file__ ).parent / "resources" / "ignore_tag.ipynb"
107109 run = NotebookRun (nb , 300 )
108110 res : NotebookResult = run .execute ()
109111 assert res .error == None
110112
111- def test_when_raises_exc_tag_then_succeeds (self , testdir2 : Testdir ):
113+ def test_when_raises_exc_tag_then_succeeds (self , testdir2 : Never ):
112114 nb = Path (__file__ ).parent / "resources" / "raises_tag.ipynb"
113115 run = NotebookRun (nb , 300 )
114116 res : NotebookResult = run .execute ()
115117 assert res .error == None
116118
117- def test_when_mock_then_succeeds (self , testdir2 : Testdir ):
119+ def test_when_mock_then_succeeds (self , testdir2 : Never ):
118120 nb = Path (__file__ ).parent / "resources" / "mock.ipynb"
119121 run = NotebookRun (nb , 300 )
120122 res : NotebookResult = run .execute ()
0 commit comments