February 2022
Intermediate to advanced
274 pages
6h 28m
English
When we used function parametrization, pytest called our test function once each for every set of argument values we provided. With fixture parametrization, we shift those parameters to a fixture. pytest will then call the fixture once each for every set of values we provide. Then downstream, every test function that depends on the fixture will be called, once each for every fixture value.
Also, the syntax is different:
| | @pytest.fixture(params=["done", "in prog", "todo"]) |
| | def start_state(request): |
| | return request.param |
| | |
| | |
| | def test_finish(cards_db, start_state): |
| | c = Card("write a book", state=start_state) |
| | index = cards_db.add_card(c) |
| | cards_db.finish(index) |
| | card = cards_db.get_card(index) ... |
Read now
Unlock full access