@@ -81,8 +81,16 @@ def pytest_addoption(parser):
8181
8282 group .addoption ('--current-env' , action = 'store_true' ,
8383 help = 'Force test execution to use a python kernel in '
84- 'the same enviornment that py.test was '
85- 'launched from.' )
84+ 'the same environment that py.test was '
85+ 'launched from. Without this flag, the kernel stored '
86+ 'in the notebook is used by default. '
87+ 'See also: --nbval-kernel-name' )
88+
89+ group .addoption ('--nbval-kernel-name' , action = 'store' , default = None ,
90+ help = 'Force test execution to use the named kernel. '
91+ 'If a kernel is not named, the kernel stored in the '
92+ 'notebook is used by default. '
93+ 'See also: --current-env' )
8694
8795 group .addoption ('--nbval-cell-timeout' , action = 'store' , default = 2000 ,
8896 type = float ,
@@ -103,6 +111,10 @@ def pytest_configure(config):
103111 from .nbdime_reporter import NbdimeReporter
104112 reporter = NbdimeReporter (config , sys .stdout )
105113 config .pluginmanager .register (reporter , 'nbdimereporter' )
114+ if config .option .nbval or config .option .nbval_lax :
115+ if config .option .nbval_kernel_name and config .option .current_env :
116+ raise ValueError ("--current-env and --nbval-kernel-name are mutually exclusive." )
117+
106118
107119
108120def pytest_collect_file (path , parent ):
@@ -227,9 +239,12 @@ def setup(self):
227239 Called by pytest to setup the collector cells in .
228240 Here we start a kernel and setup the sanitize patterns.
229241 """
230-
242+ # we've already checked that --current-env and
243+ # --nbval-kernel-name were not both supplied
231244 if self .parent .config .option .current_env :
232245 kernel_name = CURRENT_ENV_KERNEL_NAME
246+ elif self .parent .config .option .nbval_kernel_name :
247+ kernel_name = self .parent .config .option .nbval_kernel_name
233248 else :
234249 kernel_name = self .nb .metadata .get (
235250 'kernelspec' , {}).get ('name' , 'python' )
0 commit comments