Repository navigation
What should I do if the scope of the parametrize is overridden by the fixture? #11622
Replies: 1 comment
|
Hi @1766569880 The behavior in your example is expected. These two scopes are independent: @pytest.fixture(scope="module", autouse=True)
def inDeviceModelMgr():
...means Meanwhile: @pytest.mark.parametrize(..., scope="function")means the parametrized test gets one invocation per parameter set. So with five parameter rows, the expected result is: The parametrization does not change the scope of that unrelated autouse fixture. If you need the setup in @pytest.fixture(scope="function", autouse=True)
def inDeviceModelMgr():
...If instead the fixture itself needs to receive the parameter value, use indirect parametrization of that fixture. There is also a separate issue in the example: except Exception as e:
print(e)swallows setup failures. If fixture setup fails, normally you should re-raise the exception so pytest reports the test as an error rather than continuing with an invalid state. Please mark this answer as accepted if it helped, thank you. |
Uh oh!
There was an error while loading. Please reload this page.
There is a situation where the scope of @pytest.mark.parametrize and @pytest.fixture is overwritten, I think the fixture is the module level, and the parametrize is the function level should not be overridden. The parametrize is executed multiple times, and the fixture is executed only once
All reactions