February 2022
Intermediate to advanced
274 pages
6h 28m
English
You can define a function to generate identifiers by using the ids parameter. Often the builtin str or repr functions work fine.
Let’s try using str as an ID function:
| | card_list = [ |
| | Card("foo", state="todo"), |
| | Card("foo", state="in prog"), |
| | Card("foo", state="done"), |
| | ] |
| | |
| » | @pytest.mark.parametrize("starting_card", card_list, ids=str) |
| | def test_id_str(cards_db, starting_card): |
| | ... |
Here we added ids=str. We also moved the list of cards to a named variable to allow shorter code samples in the rest of this section.
Here’s what our node IDs look like now:
| | $ pytest -v test_ids.py::test_id_str |
| | ========================= test session starts ========================== |
| |