-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Testing an __init__.py
file tests the entire package
#9263
Comments
I will try to make some time to look at this, but in the meantime it would be helpful for narrowing down the issue if you can check whether this is specific to doctests, or happens in general (with regular test functions). |
OK, note I changed the name to They seem to be consistent, but I'm not sure if expected. % tree
.
└── package
├── __init__.py
└── test_me_not.py
% cat package/__init__.py
def test_good():
assert round(22/7, 2) == 3.14
% cat package/test_me_not.py
def test_bad():
assert 2 + 2 == 5 % pip install pytest==6.1.2
% pytest -q --tb=no package/__init__.py
F [100%]
=============================== short test summary info ===============================
FAILED package/test_me_not.py::test_bad - assert (2 + 2) == 5
1 failed in 0.01s
% pip install pytest==6.2.0
% pytest -q --tb=no package/__init__.py
F [100%]
=============================== short test summary info ===============================
FAILED package/test_me_not.py::test_bad - assert (2 + 2) == 5
1 failed in 0.01s
|
Is this a duplicate of #8976? |
Thank you for finding this. It doesn't seem to be exactly the same issue. The MRE in #8976 runs one % tree
.
└── foo_tests
├── __init__.py
├── test_a.py
└── test_b.py % pytest --no-header foo_tests/__init__.py
======================== test session starts =========================
collected 2 items
foo_tests/test_a.py .. [100%]
========================= 2 passed in 0.01s ========================== % pytest --no-header --doctest-modules foo_tests/__init__.py
======================== test session starts =========================
collected 4 items
foo_tests/test_a.py .. [ 50%]
foo_tests/test_b.py .. [100%]
========================= 4 passed in 0.03s ========================== |
It causes pytest to run some of the tests twice (and they fail the second time because they have exhausted a generator passed as a test fixture). This happens with pytest 6.2.5 (Ubuntu 22.04) but not pytest 4.6.9 (Ubuntu 20.04). It looks like <pytest-dev/pytest#9263>.
Still exists in
|
….py` Module Previously it would collect the entire package, but this is not what users expect. Refs pytest-dev#3749 Fixes pytest-dev#8976 Fixes pytest-dev#9263 Fixes pytest-dev#9313
….py` Module Previously it would collect the entire package, but this is not what users expect. Refs pytest-dev#3749 Fixes pytest-dev#8976 Fixes pytest-dev#9263 Fixes pytest-dev#9313
….py` Module Previously it would collect the entire package, but this is not what users expect. Refs pytest-dev#3749 Fixes pytest-dev#8976 Fixes pytest-dev#9263 Fixes pytest-dev#9313
….py` Module Previously it would collect the entire package, but this is not what users expect. Refs pytest-dev#3749 Fixes pytest-dev#8976 Fixes pytest-dev#9263 Fixes pytest-dev#9313
….py` Module Previously it would collect the entire package, but this is not what users expect. Refs pytest-dev#3749 Fixes pytest-dev#8976 Fixes pytest-dev#9263 Fixes pytest-dev#9313
I found a difference between 6.1.2 and 6.2.0. I would have expected the behavior of only testing
package/__init__.py
, but in 6.2.0 it tests the entirety ofpackage/
.I think it might be due to #8016 but I am not familiar with the internals of this library.
The text was updated successfully, but these errors were encountered: