Skip to Main Content
Python Testing with pytest
book

Python Testing with pytest

by Brian Okken
February 2022
Intermediate to advanced content levelIntermediate to advanced
274 pages
6h 28m
English
Pragmatic Bookshelf
Content preview from Python Testing with pytest

Using Indirect Parametrization

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( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Testing with pytest

Python Testing with pytest

Brian Okken

Publisher Resources

ISBN: 9781680509427Errata Page