- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.9k
Closed
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectly
Description
I have a following tests structure

with such fixtures:
# package_1/conftest.py
import pytest
@pytest.fixture(autouse=True, scope="package")
def some_fixture1():
    print("\n------------Setup package 1")
    yield
    print("\n------------ Teardown package 1")
and
# package_2/conftest.py
import pytest
@pytest.fixture(autouse=True, scope="package")
def some_fixture2():
    print("\n------------Setup package 2")
    yield
    print("\n------------Teardown package 2")
and tests
# package_1/nested_dir/test_package_1.py
def test_1():
    print("\n------------running test_1")
    assert True
and
# package_2/test_package_2.py
def test_1():
    print("\n------------running test_2")
    assert True
When I run the tests I would expect the package_1 teardown to happen before setup of package_2, but this is not what is happening. Instead, teardown happens at the end. See output:

But when I move the test file out of the nested_dir so the file structure looks like this:

the teardown order seems to be correct.

Anyways I would love to have a correct teardown order for nested tests file structure.
Pip list output:
(venv) ➜  pythonProject pip list          
Package    Version
---------- -------
iniconfig  2.0.0
packaging  23.2
pip        22.3.1
pluggy     1.3.0
pytest     7.4.2
setuptools 65.5.1
wheel      0.38.4
Operating system:
Macos Ventura 13.0
Metadata
Metadata
Assignees
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectly