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

Fixture inheritance problem #2534

Closed
mjozefcz opened this issue Jun 27, 2017 · 1 comment
Closed

Fixture inheritance problem #2534

mjozefcz opened this issue Jun 27, 2017 · 1 comment

Comments

@mjozefcz
Copy link

I noticed some strange problem with fixtures inheritance - only fixtures from "BaseFirst" class are executed. Fixtures from "BaseSecond" class are not.

Version: pytest==3.1.2

Considering example:

conftest.py:

#!/usr/bin/env python
import pytest

@pytest.fixture(scope="class")
def fixture_1(request):
    print('fixture_1')

@pytest.fixture(scope="class")
def fixture_2(request):
    print('fixture_2')

@pytest.fixture(scope="class")
def fixture_3(request):
    print('fixture_3')

test.py:

#!/usr/bin/env python

import pytest

@pytest.mark.usefixtures(
    "fixture_1",
)
class BaseFirst(object):
    def test_print_fixture_1(self):
        pass

@pytest.mark.usefixtures(
    "fixture_2",
)
class BaseSecond(object):
    def test_print_fixture_2(self):
        pass

@pytest.mark.usefixtures(
    "fixture_3",
)
class TestCase(BaseFirst, BaseSecond):
    def test_print_fixture_3(self):
        pass

Result:

python -m pytest -svl tests.py::TestCase
================================================ test session starts ================================================
platform linux2 -- Python 2.7.12+, pytest-3.1.2, py-1.4.34, pluggy-0.4.0 -- /usr/bin/python
cachedir: .cache
rootdir: /root/tmp, inifile:
plugins: timeout-1.2.0
collected 3 items 

tests.py::TestCase::test_print_fixture_1 fixture_1
fixture_3
PASSED
tests.py::TestCase::test_print_fixture_2 PASSED
tests.py::TestCase::test_print_fixture_3 PASSED

============================================= 3 passed in 0.01 seconds ==============================================

Expected result:

python -m pytest -svl tests.py::TestCase
================================================ test session starts ================================================
platform linux2 -- Python 2.7.12+, pytest-3.1.2, py-1.4.34, pluggy-0.4.0 -- /usr/bin/python
cachedir: .cache
rootdir: /root/tmp, inifile:
plugins: timeout-1.2.0
collected 3 items 

tests.py::TestCase::test_print_fixture_1 fixture_1
fixture_2
fixture_3
PASSED
tests.py::TestCase::test_print_fixture_2 PASSED
tests.py::TestCase::test_print_fixture_3 PASSED

============================================= 3 passed in 0.01 seconds ==============================================

@RonnyPfannschmidt
Copy link
Member

this is a duplicate of #535

im working on a fix but it might take until pytest 3.3 to get 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