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 --lf does not work if __init__.py files are present #7894

Closed
deb17 opened this issue Oct 14, 2020 · 2 comments
Closed

pytest --lf does not work if __init__.py files are present #7894

deb17 opened this issue Oct 14, 2020 · 2 comments

Comments

@deb17
Copy link

deb17 commented Oct 14, 2020

When there are failing tests in sibling sub-directories of the tests directory with __init__.py files, pytest --lf runs the failing tests from only one of the directories, not all the tests that failed on the last run. We need to use __init.py__ files if test files in different directories have the same name. But then pytest --lf fails to run as expected. If the __init__.py files are removed, then the --lf option runs all the failing tests.

pip list output:

Package            Version Location
------------------ ------- ------------------------------------
attrs              19.3.0
autopep8           1.5.2
click              7.1.2
coverage           5.3
entrypoints        0.3
flake8             3.7.9
importlib-metadata 1.6.0
iniconfig          1.0.1
mccabe             0.6.1
more-itertools     8.2.0
packaging          20.3
pip                20.1
pkg-resources      0.0.0
pluggy             0.13.1
py                 1.9.0
pycodestyle        2.5.0
pyflakes           2.1.1
pyparsing          2.4.7
pytest             6.1.1
pytest-cov         2.10.1
setuptools         39.0.1
six                1.14.0
tasks              0.1.0   /home/dp/testing/code/tasks_proj/src
tinydb             3.15.1
toml               0.10.1
wcwidth            0.1.9
zipp               3.1.0

pytest version - 6.1.1
OS - Ubuntu 18.04

Example

Test directory structure
--------------------------
tests/
  __init__.py
  func/
    __init__.py
    test_one.py
  unit/
    __init__.py
    test_one.py

Contents of func/test_one.py
----------------------------
def test_ne_one():
    assert 5 != 5

Contents of unit/test_one.py
-----------------------------
def test_eq_one():
    assert 1 == 2

Running pytest from tests/ directory reports 2 failing tests. But pytest --lf runs only 1 test - func/test_one.py - and skips the other. If the __init__.py files are removed and the test files are given different names, then pytest --lf runs both tests as expected.

@bluetech
Copy link
Member

Thanks for the detailed report @deb17. This is a duplicate of #7758, but the reproduction you provided will help in resolving it.

@deb17
Copy link
Author

deb17 commented Oct 14, 2020

I searched a lot on Google for the issue. But the issue you mention did not show up. So I assumed no issue was present. Sorry about it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants