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
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:
Tests
When I run the tests I see the API responses printed 4 times(twice for
aparameter and twice forbparameter). I was expecting it to be printed just twice(once for both the parameters -aandb) since both the tests use same set of parameters and the fixed is scopedsession. Obviously, if I don't parameterize the fixture the api response is printed once. Pytest version is7.4.2