diff --git a/CHANGES.rst b/CHANGES.rst index 48cb45e..583a87d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,8 @@ 1.1.0 (unreleased) ================== +- Fix module level ``__doctest_requires__``. [#228] + - Versions of Python <3.8 are no longer supported. [#217] diff --git a/pytest_doctestplus/plugin.py b/pytest_doctestplus/plugin.py index 859704e..ca647f0 100644 --- a/pytest_doctestplus/plugin.py +++ b/pytest_doctestplus/plugin.py @@ -673,6 +673,7 @@ def check_required_modules(cls, mods): if mod in cls._import_cache: if not cls._import_cache[mod]: return False + continue if cls._module_checker.check(mod): cls._import_cache[mod] = True @@ -714,9 +715,17 @@ def test_filter(test): for pats, mods in reqs.items(): if not isinstance(pats, tuple): pats = (pats,) + for pat in pats: - if not fnmatch.fnmatch(test.name, '.'.join((name, pat))): - continue + if pat == '*': + pass + elif pat == '.' and test.name == name: + pass + elif fnmatch.fnmatch(test.name, '.'.join((name, pat))): + pass + else: + continue # The pattern does not apply + if not self.check_required_modules(mods): return False return True diff --git a/tests/python/doctests.py b/tests/python/doctests.py index d6841bb..391fd96 100644 --- a/tests/python/doctests.py +++ b/tests/python/doctests.py @@ -1,5 +1,12 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst +""" +Also module level skips should be matched with `*` and `.`, test at least +the `.` version (the star would match all others too). + +>>> import foobar +""" + __doctest_skip__ = [ 'skip_this_test', 'ClassWithSomeBadDocTests.this_test_fails', @@ -7,6 +14,7 @@ ] __doctest_requires__ = { + '.': ['foobar'], 'depends_on_foobar': ['foobar'], 'depends_on_foobar_submodule': ['foobar.baz'], 'depends_on_two_modules': ['os', 'foobar'],