Skip to content

Package fixture doesn't respect dependency #7400

@voronind

Description

@voronind
  1. Package fixture doesn't tear down after dir "exiting".
  2. Package fixture doesn't use another package fixture depends on it. See comment in pytest output.

Ubuntu 20.04, pytest==5.4.3, python 3.6

expr/
    test1/
        conftest.py
        test_1.py
    test2/
        conftest.py
        test_2.py
    conftest.py

expr/test1/conftest.py

from pytest import fixture

@fixture('package')
def company():
    print('\ncompany == 1')
    yield 1
    print('\ncompany == 1 tear down')

expr/test1/test_1.py

def test_1(company2):
    assert company2 == 1

expr/test2 is same but 2 instead of 1

expr/conftest.py

from pytest import fixture

@fixture('package')
def company2(company):
    print('\ncompany2 == ', company)
    yield company
    print('\ncompany2 == ', company, ' tear down')

Ouput:

================ test session starts ====================
platform linux -- Python 3.6.9, pytest-5.4.3, py-1.7.0, pluggy-0.13.1
rootdir: /home/voronin/projects/sintez_addons, inifile: setup.cfg
collected 2 items                                                                                                                                                                                                                            

expr/test_1/test_1.py 
company == 1

company2 ==  1
PASSED
expr/test_2/test_2.py 
# <- Why there is no company == 1 tear down. Why company2 doesn't use company==2?
company == 2
FAILED           
company2 ==  1  tear down

company == 2 tear down

company == 1 tear down


============ FAILURES ==================
___________________ test_2 ________________

company2 = 1

    def test_2(company2):
>       assert company2 == 2
E       assert 1 == 2

expr/test_2/test_2.py:3: AssertionError
========== short test summary info =======================
FAILED expr/test_2/test_2.py::test_2 - assert 1 == 2
=========== 1 failed, 1 passed in 0.08s ======================

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions