Skip to content

Scope of parameterized fixture doesn't work #12086

Description

@gjambaisivanandham

I am fairly new to pytest and I see that scope of a parameterized fixture is not working.

Here is an example of the fixture and the test:

@pytest.fixture(scope='session')
def my_fixture(request):
       # make some API calls
       # print API call response
       return response

Tests

@pytest.mark.parametrize('my_fixture',['a','b']):
def test_scenario_1(my_fixture):
      assert response['text'] == 'abc' 

@pytest.mark.parametrize('my_fixture',['a','b']):
def test_scenario_2(my_fixture):
      assert response['image'] == 'def' 

When I run the tests I see the API responses printed 4 times(twice for a parameter and twice for b parameter). I was expecting it to be printed just twice(once for both the parameters - a and b) since both the tests use same set of parameters and the fixed is scoped session. Obviously, if I don't parameterize the fixture the api response is printed once. Pytest version is 7.4.2

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions