February 2022
Intermediate to advanced
274 pages
6h 28m
English
In the previous example using dictionaries, the parameter values came from a function, text_variants.values(). We can write our own functions to generate parameter values.
Let’s move the generation of text variants into a function, text_variants(), which we’ll define shortly. We can then call that function for our parameter values:
| | @pytest.mark.parametrize("variant", text_variants()) |
| | def test_summary(cards_db, variant): |
| | i = cards_db.add_card(Card(summary=variant)) |
| | c = cards_db.get_card(i) |
| | assert c.summary == variant |
Now we need to define our text_variants() function. It can really be anything, but let’s use a dictionary like before, and use it to generate pytest.param
Read now
Unlock full access