@@ -81,8 +81,16 @@ def pytest_addoption(parser):
81
81
82
82
group .addoption ('--current-env' , action = 'store_true' ,
83
83
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' )
86
94
87
95
group .addoption ('--nbval-cell-timeout' , action = 'store' , default = 2000 ,
88
96
type = float ,
@@ -103,6 +111,10 @@ def pytest_configure(config):
103
111
from .nbdime_reporter import NbdimeReporter
104
112
reporter = NbdimeReporter (config , sys .stdout )
105
113
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
+
106
118
107
119
108
120
def pytest_collect_file (path , parent ):
@@ -227,9 +239,12 @@ def setup(self):
227
239
Called by pytest to setup the collector cells in .
228
240
Here we start a kernel and setup the sanitize patterns.
229
241
"""
230
-
242
+ # we've already checked that --current-env and
243
+ # --nbval-kernel-name were not both supplied
231
244
if self .parent .config .option .current_env :
232
245
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
233
248
else :
234
249
kernel_name = self .nb .metadata .get (
235
250
'kernelspec' , {}).get ('name' , 'python' )
0 commit comments