Skip to content

Commit 827a054

Browse files
authored
Merge pull request #199 from scipy/doctest-only
ENH: add --doctest-only-doctests={true,false} option
2 parents 13d62f3 + 5a80db2 commit 827a054

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ $ pytest --pyargs <your-package> --doctest-modules --doctest-collect=api
151151
See [More fine-grained control](#more-fine-grained-control) section
152152
for details on how to customize the behavior.
153153

154+
** NOTE ** Currently, `pytest --doctest-modules` only collects doctests and skips
155+
'regular' unit tests. This differs from the vanilla `pytest` behavior, which collects
156+
both doctests and unit tests.
157+
The behavior will change in a future version: `scipy-doctest==2.0` **will change the
158+
default** to align with the vanilla `pytest`.
159+
160+
To retain the current behavior, use the `--doctest-only-doctests` CLI option:
161+
162+
```
163+
$ pytest --doctest-modules --doctest-only-doctests
164+
```
165+
166+
is unambiguous and will behave identically in the current version 1.8 and upcoming
167+
versions of `scipy-doctest`.
168+
169+
154170
### Basic usage
155171

156172
The use of `pytest` is optional, and you can use the `doctest` layer API.
@@ -291,11 +307,11 @@ NumPy wraps `scipy-doctest` with the `spin` command
291307
$ spin check-docs
292308
```
293309

294-
SciPy wraps `scipy-doctest` with custom `dev.py` commands:
310+
In SciPy, the name of the `spin` command is `smoke-docs`::
295311

296312
```
297-
$ python dev.py smoke-docs # check docstrings
298-
$ python dev.py smoke-tutorials # ReST user guide tutorials
313+
$ spin smoke-docs # check docstrings
314+
$ spin smoke-tutorials # ReST user guide tutorials
299315
```
300316

301317
## Rough edges and sharp bits

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)