Skip to content

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

@deb17

Description

@deb17

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions