Skip to content

Commit d6a8889

Browse files
committed
Add option to specify a kernel.
1 parent 8593e7d commit d6a8889

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

nbval/plugin.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)