February 2022
Intermediate to advanced
274 pages
6h 28m
English
The final parametrization technique we’re going to look at is indirect parametrization. An indirect parameter is one that gets passed to a fixture before it gets sent to the test function. Indirect parametrization allows us to perform work based on the parameter value.
The way it works is to set indirect to a list of parameter names you want to be indirect, like indirect=["param1", "param2"]. You can also set indirect=True if you want all parameters to be indirect. Then you need a fixture with the same name as the parameter.
As an example, let’s say we have expanded Cards to have different access rights for different user roles. We can parametrize a test with a user parameter:
| | @pytest.mark.parametrize( ... |