Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest --doctest-modules crashes on file-level __test__ = False #11730

Open
kaddkaka opened this issue Dec 21, 2023 · 7 comments
Open

pytest --doctest-modules crashes on file-level __test__ = False #11730

kaddkaka opened this issue Dec 21, 2023 · 7 comments
Labels
plugin: doctests related to the doctests builtin plugin

Comments

@kaddkaka
Copy link

A file level __test__ = False succesfully stops pytest from collecting any test from that file, however when running pytest --doctest- modules on the same file, this error appears:

/sw/Python/Ubuntu-22.04/3.10.5/lib/python3.10/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
/sw/Python/Ubuntu-22.04/3.10.5/lib/python3.10/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
/sw/Python/Ubuntu-22.04/3.10.5/lib/python3.10/site-packages/_pytest/doctest.py:587: in collect
    for test in finder.find(module, module.__name__):
/sw/Python/Ubuntu-22.04/3.10.5/lib/python3.10/doctest.py:940: in find
    self._find(tests, obj, name, module, source_lines, globs, {})
/sw/Python/Ubuntu-22.04/3.10.5/lib/python3.10/site-packages/_pytest/doctest.py:536: in _find
    super()._find(  # type:ignore[misc]
/sw/Python/Ubuntu-22.04/3.10.5/lib/python3.10/doctest.py:1018: in _find
    for valname, val in getattr(obj, '__test__', {}).items():
E   AttributeError: 'bool' object has no attribute 'items'

It's enoough to have a file with only this content to see the behavior:

__test__ = False

Version: pytest 7.4.3

@RonnyPfannschmidt
Copy link
Member

This looks like a issue with the stdlib

@kaddkaka
Copy link
Author

@RonnyPfannschmidt do you have any idea on how to investigate or fix?

@RonnyPfannschmidt
Copy link
Member

based on https://docs.python.org/3/library/doctest.html#which-docstrings-are-examined the code in the stdlib is incorrect, a upstream bug needs to be opened

@kaddkaka
Copy link
Author

Thanks, I tested __test__ = {} which seems to have the intended effect on both pytest and doctest.

Where would such a bug be opened? python/cpython?

@RonnyPfannschmidt
Copy link
Member

cpython

@ValdonVitija
Copy link

There is a workaround. I had the same problem and this is how I 'fixed' it. Instead of using :

__test__ = False,

do this:

pytestmark = pytest.mark.skip

@kaddkaka
Copy link
Author

There is a workaround. I had the same problem and this is how I 'fixed' it. Instead of using :

__test__ = False,

do this:

pytestmark = pytest.mark.skip

Where is this documented and what's the difference?

Why not just __test__ = {}?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: doctests related to the doctests builtin plugin
Projects
None yet
Development

No branches or pull requests

4 participants