@@ -29,6 +29,28 @@ def pytest_addoption(parser):
29
29
dest = "collection_strategy"
30
30
)
31
31
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
+ )
32
54
33
55
def pytest_configure (config ):
34
56
"""
@@ -49,7 +71,13 @@ def pytest_ignore_collect(collection_path, config):
49
71
This function is used to exclude the 'tests' directory and test modules when
50
72
the `--doctest-modules` option is used.
51
73
"""
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
+ ):
53
81
path_str = str (collection_path )
54
82
if "tests" in path_str or "test_" in path_str :
55
83
return True
0 commit comments