February 2022
Intermediate to advanced
274 pages
6h 28m
English
So far we’ve written test functions within test modules within a file system directory. That structuring of test code actually works quite well and is sufficient for many projects. However, pytest also allows us to group tests with classes.
Let’s take a few of the test functions related to Card equality and group them into a class:
| | class TestEquality: |
| | def test_equality(self): |
| | c1 = Card("something", "brian", "todo", 123) |
| | c2 = Card("something", "brian", "todo", 123) |
| | assert c1 == c2 |
| | def test_equality_with_diff_ids(self): |
| | c1 = Card("something", "brian", "todo", 123) |
| | c2 = Card("something", "brian", "todo", 4567) |
| | assert c1 == c2 |
| | |
| | def test_inequality ... |
Read now
Unlock full access