Skip to content

Commit a385d5e

Browse files
committed
Rename --current-env and --sanitize-with
1 parent 98bd556 commit a385d5e

File tree

9 files changed

+33
-17
lines changed

9 files changed

+33
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ Specify `-p no:python` if you would like to execute notebooks only. Alternativel
7272

7373
py.test --nbval my_notebook.ipynb
7474

75-
If the output lines are going to be sanitized, an extra flag, `--sanitize-with`
75+
If the output lines are going to be sanitized, an extra flag, `--nbval-sanitize-with`
7676
together with the path to a confguration file with regex expressions, must be passed,
7777
i.e.
7878

79-
py.test --nbval my_notebook.ipynb --sanitize-with path/to/my_sanitize_file
79+
py.test --nbval my_notebook.ipynb --nbval-sanitize-with path/to/my_sanitize_file
8080

8181
where `my_sanitize_file` has the following structure.
8282

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: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ def pytest_addoption(parser):
7979
help="Run Jupyter notebooks, only validating output on "
8080
"cells marked with # NBVAL_CHECK_OUTPUT")
8181

82-
group.addoption('--sanitize-with',
82+
group.addoption('--nbval-sanitize-with',
8383
help='File with regex expressions to sanitize '
8484
'the outputs. This option only works when '
8585
'the --nbval flag is passed to py.test')
8686

87-
group.addoption('--current-env', action='store_true',
87+
group.addoption('--nbval-current-env', action='store_true',
8888
help='Force test execution to use a python kernel in '
8989
'the same enviornment that py.test was '
9090
'launched from.')
@@ -97,6 +97,12 @@ def pytest_addoption(parser):
9797
type=float,
9898
help='Timeout for kernel startup, in seconds.')
9999

100+
group.addoption('--sanitize-with',
101+
help='(deprecated) Alias of --nbval-sanitize-with')
102+
103+
group.addoption('--current-env', action='store_true',
104+
help='(deprecated) Alias of --nbval-current-env')
105+
100106
term_group = parser.getgroup("terminal reporting")
101107
term_group._addoption(
102108
'--nbdime', action='store_true',
@@ -108,6 +114,16 @@ def pytest_configure(config):
108114
from .nbdime_reporter import NbdimeReporter
109115
reporter = NbdimeReporter(config, sys.stdout)
110116
config.pluginmanager.register(reporter, 'nbdimereporter')
117+
if config.option.sanitize_with:
118+
warnings.warn("--sanitize-with has been renamed to --nbval-sanitize-with", DeprecationWarning)
119+
if config.option.nbval_sanitize_with:
120+
raise ValueError("--sanitize-with and --nbval-sanitize-with were both supplied.")
121+
config.option.nbval_sanitize_with = config.option.sanitize_with
122+
if config.option.current_env:
123+
warnings.warn("--current-env has been renamed to --nbval-current-env", DeprecationWarning)
124+
if config.option.nbval_current_env:
125+
raise ValueError("--current-env and --nbval-current-env were both supplied.")
126+
config.option.nbval_current_env = config.option.current_env
111127

112128

113129
def pytest_collect_file(path, parent):
@@ -233,7 +249,7 @@ def setup(self):
233249
Here we start a kernel and setup the sanitize patterns.
234250
"""
235251

236-
if self.parent.config.option.current_env:
252+
if self.parent.config.option.nbval_current_env:
237253
kernel_name = CURRENT_ENV_KERNEL_NAME
238254
else:
239255
kernel_name = self.nb.metadata.get(
@@ -266,8 +282,8 @@ def get_sanitize_files(self):
266282
this is likely to change in the future
267283
268284
"""
269-
if self.parent.config.option.sanitize_with is not None:
270-
return [self.parent.config.option.sanitize_with]
285+
if self.parent.config.option.nbval_sanitize_with is not None:
286+
return [self.parent.config.option.nbval_sanitize_with]
271287
else:
272288
return []
273289

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)