February 2022
Intermediate to advanced
274 pages
6h 28m
English
There’s a little bit of a problem with our test code right now. The problem is the tests both depend on the database being empty to start with, but they use the same database instance in the module-scope and session-scope versions.
The problem becomes very clear if we add a third test:
| | def test_three(cards_db): |
| | cards_db.add_card(cards.Card("first")) |
| | cards_db.add_card(cards.Card("second")) |
| | cards_db.add_card(cards.Card("third")) |
| | assert cards_db.count() == 3 |
It works fine by itself, but not when it’s run after test_count.py::test_two:
| | $ pytest -v test_three.py |
| | ========================== test session starts ========================== |
| | collected 1 item |
| | |
| | test_three.py::test_three ... |
Read now
Unlock full access