Skip to content

Commit a13a03b

Browse files
authored
Merge pull request #161 from ceball/some_option_renaming
Add "nbval" into --current-env and --sanitize-with option names
2 parents deb72e6 + ce960f2 commit a13a03b

File tree

9 files changed

+34
-18
lines changed

9 files changed

+34
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ either `--nbval-kernel-name mykernel` to run all the notebooks using
7878
`mykernel`, or `--current-env` to use a kernel in the same environment
7979
in which pytest itself was launched.
8080

81-
If the output lines are going to be sanitized, an extra flag, `--sanitize-with`
81+
If the output lines are going to be sanitized, an extra flag, `--nbval-sanitize-with`
8282
together with the path to a confguration file with regex expressions, must be passed,
8383
i.e.
8484

85-
py.test --nbval my_notebook.ipynb --sanitize-with path/to/my_sanitize_file
85+
py.test --nbval my_notebook.ipynb --nbval-sanitize-with path/to/my_sanitize_file
8686

8787
where `my_sanitize_file` has the following structure.
8888

dodo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _clean_dist_cmd():
2222
def task_test():
2323
return {
2424
'actions': [
25-
_make_cmd(["py.test", "-v", "tests/", "--nbval", "--current-env", "--sanitize-with", "tests/sanitize_defaults.cfg", "--ignore", "tests/ipynb-test-samples"]),
25+
_make_cmd(["py.test", "-v", "tests/", "--nbval", "--nbval-current-env", "--nbval-sanitize-with", "tests/sanitize_defaults.cfg", "--ignore", "tests/ipynb-test-samples"]),
2626
],
2727
}
2828

nbval/plugin.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ def pytest_addoption(parser):
7474
help="Run Jupyter notebooks, only validating output on "
7575
"cells marked with # NBVAL_CHECK_OUTPUT")
7676

77-
group.addoption('--sanitize-with',
77+
group.addoption('--nbval-sanitize-with',
7878
help='File with regex expressions to sanitize '
7979
'the outputs. This option only works when '
8080
'the --nbval flag is passed to py.test')
8181

82-
group.addoption('--current-env', action='store_true',
82+
group.addoption('--nbval-current-env', action='store_true',
8383
help='Force test execution to use a python kernel in '
8484
'the same environment that py.test was '
8585
'launched from. Without this flag, the kernel stored '
@@ -100,6 +100,12 @@ def pytest_addoption(parser):
100100
type=float,
101101
help='Timeout for kernel startup, in seconds.')
102102

103+
group.addoption('--sanitize-with',
104+
help='(deprecated) Alias of --nbval-sanitize-with')
105+
106+
group.addoption('--current-env', action='store_true',
107+
help='(deprecated) Alias of --nbval-current-env')
108+
103109
term_group = parser.getgroup("terminal reporting")
104110
term_group._addoption(
105111
'--nbdime', action='store_true',
@@ -111,6 +117,16 @@ def pytest_configure(config):
111117
from .nbdime_reporter import NbdimeReporter
112118
reporter = NbdimeReporter(config, sys.stdout)
113119
config.pluginmanager.register(reporter, 'nbdimereporter')
120+
if config.option.sanitize_with:
121+
warnings.warn("--sanitize-with has been renamed to --nbval-sanitize-with", DeprecationWarning)
122+
if config.option.nbval_sanitize_with:
123+
raise ValueError("--sanitize-with and --nbval-sanitize-with were both supplied.")
124+
config.option.nbval_sanitize_with = config.option.sanitize_with
125+
if config.option.current_env:
126+
warnings.warn("--current-env has been renamed to --nbval-current-env", DeprecationWarning)
127+
if config.option.nbval_current_env:
128+
raise ValueError("--current-env and --nbval-current-env were both supplied.")
129+
config.option.nbval_current_env = config.option.current_env
114130
if config.option.nbval or config.option.nbval_lax:
115131
if config.option.nbval_kernel_name and config.option.current_env:
116132
raise ValueError("--current-env and --nbval-kernel-name are mutually exclusive.")
@@ -239,9 +255,9 @@ def setup(self):
239255
Called by pytest to setup the collector cells in .
240256
Here we start a kernel and setup the sanitize patterns.
241257
"""
242-
# we've already checked that --current-env and
258+
# we've already checked that --nbval-current-env and
243259
# --nbval-kernel-name were not both supplied
244-
if self.parent.config.option.current_env:
260+
if self.parent.config.option.nbval_current_env:
245261
kernel_name = CURRENT_ENV_KERNEL_NAME
246262
elif self.parent.config.option.nbval_kernel_name:
247263
kernel_name = self.parent.config.option.nbval_kernel_name
@@ -276,8 +292,8 @@ def get_sanitize_files(self):
276292
this is likely to change in the future
277293
278294
"""
279-
if self.parent.config.option.sanitize_with is not None:
280-
return [self.parent.config.option.sanitize_with]
295+
if self.parent.config.option.nbval_sanitize_with is not None:
296+
return [self.parent.config.option.nbval_sanitize_with]
281297
else:
282298
return []
283299

tests/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
PYTEST ?= py.test
2-
TEST_OPTIONS ?= -v --current-env
2+
TEST_OPTIONS ?= -v --nbval-current-env
33

44
all: test
55

66
test:
77
$(PYTEST) $(TEST_OPTIONS) .
8-
$(PYTEST) --nbval --current-env --sanitize-with sanitize_defaults.cfg sample_notebook.ipynb
9-
$(PYTEST) --nbval --current-env latex-example.ipynb
8+
$(PYTEST) --nbval --nbval-current-env --nbval-sanitize-with sanitize_defaults.cfg sample_notebook.ipynb
9+
$(PYTEST) --nbval --nbval-current-env latex-example.ipynb
1010

1111
.PHONY: all test

tests/test_collect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_collection_nbval(testdir):
4444
_write_nb(sources, os.path.join(str(testdir.tmpdir), 'test_collection.ipynb'))
4545

4646
# Run tests
47-
items, recorder = testdir.inline_genitems('--nbval', '--current-env')
47+
items, recorder = testdir.inline_genitems('--nbval', '--nbval-current-env')
4848

4949
# Debug output:
5050
for item in items:
@@ -60,7 +60,7 @@ def test_collection_nbval_lax(testdir):
6060
_write_nb(sources, os.path.join(str(testdir.tmpdir), 'test_collection.ipynb'))
6161

6262
# Run tests
63-
items, recorder = testdir.inline_genitems('--nbval-lax', '--current-env')
63+
items, recorder = testdir.inline_genitems('--nbval-lax', '--nbval-current-env')
6464

6565
# Debug output:
6666
for item in items:

tests/test_coverage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_sum():
4646
str(testdir.tmpdir), 'test_coverage.ipynb'))
4747

4848
# Run tests
49-
result = testdir.runpytest_inprocess('--nbval', '--current-env', '--cov', '.')
49+
result = testdir.runpytest_inprocess('--nbval', '--nbval-current-env', '--cov', '.')
5050

5151
# Check tests went off as they should:
5252
assert result.ret == 0

tests/test_ignore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_conf_ignore_stderr(testdir):
5151
str(testdir.tmpdir), 'test_ignore.ipynb'))
5252

5353
# Run tests
54-
result = testdir.runpytest_subprocess('--nbval', '--current-env', '.')
54+
result = testdir.runpytest_subprocess('--nbval', '--nbval-current-env', '.')
5555

5656
# Check tests went off as they should:
5757
assert result.ret == 0

tests/test_timeouts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_timeouts(testdir):
4646
str(testdir.tmpdir), 'test_timeouts.ipynb'))
4747

4848
# Run tests
49-
result = testdir.inline_run('--nbval', '--current-env', '--nbval-cell-timeout', '5', '-s')
49+
result = testdir.inline_run('--nbval', '--nbval-current-env', '--nbval-cell-timeout', '5', '-s')
5050
reports = result.getreports('pytest_runtest_logreport')
5151

5252
# Setup and teardown of cells should have no issues:

tests/test_unit_tests_in_notebooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def create_test_cases_from_filenames():
5353
@pytest.mark.parametrize("filename, correctoutcome", testdata, ids=testnames)
5454
def test_print(filename, correctoutcome):
5555

56-
command = ["py.test", "--nbval", "-v", "--current-env", filename]
56+
command = ["py.test", "--nbval", "-v", "--nbval-current-env", filename]
5757
print("Starting parametrized test with filename={}, correctoutcome={}"
5858
.format(filename, correctoutcome))
5959
print("Command about to execute is '{}'".format(command))

0 commit comments

Comments
 (0)