@@ -86,8 +86,16 @@ def pytest_addoption(parser):
8686
8787 group .addoption ('--current-env' , action = 'store_true' ,
8888 help = 'Force test execution to use a python kernel in '
89- 'the same enviornment that py.test was '
90- 'launched from.' )
89+ 'the same environment that py.test was '
90+ 'launched from. Without this flag, the kernel stored '
91+ 'in the notebook is used by default. '
92+ 'See also: --kernel-name' )
93+
94+ group .addoption ('--kernel-name' , action = 'store' , default = None ,
95+ help = 'Force test execution to use the named kernel. '
96+ 'If a kernel is not named, the kernel stored in the '
97+ 'notebook is used by default. '
98+ 'See also: --current-env' )
9199
92100 group .addoption ('--nbval-cell-timeout' , action = 'store' , default = 2000 ,
93101 type = float ,
@@ -224,9 +232,12 @@ def setup(self):
224232 Called by pytest to setup the collector cells in .
225233 Here we start a kernel and setup the sanitize patterns.
226234 """
227-
235+ if self .parent .config .option .kernel_name and self .parent .config .option .current_env :
236+ raise ValueError ("--current-env and --kernel-name are mutually exclusive." )
228237 if self .parent .config .option .current_env :
229238 kernel_name = CURRENT_ENV_KERNEL_NAME
239+ elif self .parent .config .option .kernel_name :
240+ kernel_name = self .parent .config .option .kernel_name
230241 else :
231242 kernel_name = self .nb .metadata .get (
232243 'kernelspec' , {}).get ('name' , 'python' )
0 commit comments