February 2022
Intermediate to advanced
274 pages
6h 28m
English
To parametrize a test function, add parameters to the test definition and use the @pytest.mark.parametrize() decorator to define the sets of arguments to pass to the test, like this:
| | import pytest |
| | from cards import Card |
| | |
| | |
| | @pytest.mark.parametrize( |
| | "start_summary, start_state", |
| | [ |
| | ("write a book", "done"), |
| | ("second edition", "in prog"), |
| | ("create a course", "todo"), |
| | ], |
| | ) |
| | def test_finish(cards_db, start_summary, start_state): |
| | initial_card = Card(summary=start_summary, state=start_state) |
| | index = cards_db.add_card(initial_card) |
| | |
| | cards_db.finish(index) |
| | |
| | card = cards_db.get_card(index) |
| | assert card.state == "done" |
The test_finish() function now ...
Read now
Unlock full access