Skip to content

indirect=True in parametrize breaks fixture scopes #570

Closed
@pytestbot

Description

@pytestbot

Originally reported by: Ivan Kalinin (BitBucket: PuPSSMaN, GitHub: PuPSSMaN)


The following test:

#!python

import pytest

@pytest.fixture(scope='class')
def my_profile(request):
    print 'Setting up profile with param', getattr(request, 'param', 'Nothing')


@pytest.mark.parametrize('my_profile', ['pewpew', 'ololo'], indirect=True)
class TestClassOne:
    def test_foo(self, my_profile):
        pass

    def test_bar(self, my_profile):
        pass

Outputs this:

#!text

(pytest)pupssman@dirigible:~$ py.test test_1.py  -sv
================================================ test session starts =================================================
platform linux2 -- Python 2.7.4 -- py-1.4.23 -- pytest-2.6.1 -- /home/pupssman/venv/pytest/bin/python
plugins: qabs-yadt, allure-adaptor, contextfixture, capturelog, xdist
collected 4 items 

test_1.py::TestClassOne::test_foo[pewpew] Setting up profile with param pewpew
PASSED
test_1.py::TestClassOne::test_foo[ololo] Setting up profile with param ololo
PASSED
test_1.py::TestClassOne::test_bar[pewpew] Setting up profile with param pewpew
PASSED
test_1.py::TestClassOne::test_bar[ololo] Setting up profile with param ololo
PASSED

============================================== 4 passed in 0.01 seconds ==============================================

Looks like it sets the fixture up for each test method of class independently.
However, the declaration of scope='class' should force py.test to set the fixture up only once for each parameter value for the test class. I.e., the output should be something like that:

#!text

(pytest)pupssman@dirigible:~$ py.test test_1.py  -sv
================================================ test session starts =================================================
platform linux2 -- Python 2.7.4 -- py-1.4.23 -- pytest-2.6.1 -- /home/pupssman/venv/pytest/bin/python
plugins: qabs-yadt, allure-adaptor, contextfixture, capturelog, xdist
collected 4 items 

test_1.py::TestClassOne::test_foo[pewpew] Setting up profile with param pewpew
PASSED
test_1.py::TestClassOne::test_bar[pewpew]
PASSED
test_1.py::TestClassOne::test_foo[ololo] Setting up profile with param ololo
PASSED
test_1.py::TestClassOne::test_bar[ololo]
PASSED

============================================== 4 passed in 0.01 seconds ==============================================


Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytopic: parametrizerelated to @pytest.mark.parametrizetype: 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