pytest-dev / pytest-dev/pytest
--doctest-modules ignores module-attribute docstrings
Open
Nobody has claimed this yet.
plugin: doctests
type: enhancement
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
[edit: mistakenly submitted without description]
Description
Module-level attributes with docstrings underneath (or sphinx-comments prefixed with #:) are ignored when doctesting modules.
- Standard python's
doctestmodule also ignores module-data docstrings
(so we can claim this "not a bug"), yet ... - Sphinx consider these as valid docstrings, and
- Sphinx's
doctestbuilder also validates them.
Example
Running pytest --doctest-modules on the module below named foo.py:
def f():
"""
This doctest works:
>>> 1 + 1
1
"""
a = 1
"""
But this doctest is ignored:
>>> 1 + 1
4
"""
#: Also this doctest is ignored:
#:
#: >>> 1 + 1
#: 3
b = 1
if __name__ == "__main__":
import doctest
doctest.testmod()
- raises just 1 error (
1 + 1 = 4), python foo.pyalso raises 1 error, but ...- if you setup a small site, include this module with auto-documenter, and launch
python setup.py build_sphinx -b doctest(ormake html), thedoctestsphinx-builder takes both docstring ofaandbmodule data members into account, and screams 3 times!
Versions
$ pip list|grep pytest
pytest 5.3.5
pytest-cov 2.8.1
pytest-sphinx 0.2.2
pytest-sugar 0.9.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the foo.py example and reproduce the behavior using pytest --doctest-modules, comparing it with doctest.testmod() and the Sphinx doctest builder described in the issue. The work is done when doctests in both ordinary module-attribute docstrings and #: documentation comments are discovered and validated by pytest.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100