Skip to content

Commit 231eb48

Browse files
committed
ENH: add --doctest-only-doctests={true,false} option
The default is True, for now. The plan is to make it False in v2.0, so that $ pytest --doctest-modules runs both doctests and regular tests (consistent which vanilla doctest), and then the current behavior (== only run doctests) will require $ pytest --doctest-modules --doctest-only-doctests=true
1 parent 13d62f3 commit 231eb48

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

scipy_doctest/plugin.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,28 @@ def pytest_addoption(parser):
2929
dest="collection_strategy"
3030
)
3131

32+
# We cannot add `--doctest-only` option because of
33+
# https://github.com/pytest-dev/pytest/discussions/13435
34+
#
35+
# Therefore, we add a new option, --doctest-only-doctests,
36+
# which is `true` by default, for now.
37+
#
38+
# In v2.0, it the default will become `false`, so that
39+
#
40+
# $ pytest --doctest-modules
41+
#
42+
# will run both doctests and unit tests, and the way to use the
43+
# current behavior (only run doctests, skip unit tests) will be
44+
#
45+
# $ pytest --doctest-modules --doctest-only-doctests=true
46+
#
47+
group.addoption("--doctest-only-doctests",
48+
action="store",
49+
default="true",
50+
help="Whether to only collect doctests, or also collect unit tests, too.",
51+
choices=("true", "false"),
52+
dest="doctest_only_doctests"
53+
)
3254

3355
def pytest_configure(config):
3456
"""
@@ -49,7 +71,13 @@ def pytest_ignore_collect(collection_path, config):
4971
This function is used to exclude the 'tests' directory and test modules when
5072
the `--doctest-modules` option is used.
5173
"""
52-
if config.getoption("--doctest-modules"):
74+
# XXX: in v2.0, --doctest-modules will mean "run both doctests and unit tests",
75+
# (consistent with vanilla pytest), and the way to retain the current behavior
76+
# will be to add --doctest-only-doctests=true to the CLI command
77+
if (
78+
config.getoption("--doctest-modules") and
79+
config.getoption("--doctest-only-doctests") == 'true'
80+
):
5381
path_str = str(collection_path)
5482
if "tests" in path_str or "test_" in path_str:
5583
return True

0 commit comments

Comments
 (0)