pytest-dev / pytest-dev/pytest
Leakage of NUMBER option out of docstring scope
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
- a detailed description of the bug or problem you are having
- output of
pip listfrom the virtual environment you are using - pytest and operating system versions
- minimal example if possible
This was originally noted in #9892, but there is a more targeted MRE here.
MRE
Running pytest --doctest-modules test_x.py with x=1, 2 or 3 results in the following pattern of failing and passing tests. The test inside test_wo_number incorrectly passes only on the cases (test_1.py and test_2.py) where a failing test that uses NUMBER (test_w_off_by_2_number) also exists in the same module. This leakage does not occur when there are tests that pass that utilize NUMBER (test_3.py)
# test_1.py
def test_w_number():
"""
Correctly Passes
Examples
--------
>>> 1. # doctest: +NUMBER
0.
"""
def test_w_off_by_2_number():
"""
Correctly Fails
Examples
--------
>>> 0. # doctest: +NUMBER
2.
"""
def test_wo_number():
"""
Incorrectly Passes
Examples
--------
>>> 1.
0.
"""
# test_2.py
def test_w_off_by_2_number():
"""
Correctly Fails
Examples
--------
>>> 0. # doctest: +NUMBER
2.
"""
def test_wo_number():
"""
Incorrectly Passes
Examples
--------
>>> 1.
0.
"""
# test_3.py
def test_w_number():
"""
Correctly Passes
Examples
--------
>>> 1. # doctest: +NUMBER
0.
"""
def test_wo_number():
"""
Correctly Fails
Examples
--------
>>> 1.
0.
"""
pip list
Package Version
---------- -------
attrs 21.4.0
iniconfig 1.1.1
numpy 1.22.3
packaging 21.3
pip 22.0.4
pluggy 1.0.0
py 1.11.0
pyparsing 3.0.8
pytest 7.1.2
setuptools 41.2.0
tomli 2.0.1
system version
CentOS 7.9
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
Reproduce the issue with pytest --doctest-modules test_x.py using the three MRE module variants and focus on doctest handling of the NUMBER option. Verify that an option used in one docstring does not affect another, and that the no-option example in test_wo_number fails as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100