February 2022
Intermediate to advanced
274 pages
6h 28m
English
Let’s say we know we won’t support sorting in the 1.x.x versions of the Cards application, but will in version 2.x.x. We can tell pytest to skip the test for all versions of Cards lower than than 2.x.x like this:
| | import cards |
| | from packaging.version import parse |
| | |
| | |
| | @pytest.mark.skipif( |
| | parse(cards.__version__).major < 2, |
| | reason="Card < comparison not supported in 1.x", |
| | ) |
| | def test_less_than(): |
| | c1 = Card("a task") |
| | c2 = Card("b task") |
| | assert c1 < c2 |
The skipif marker allows you to pass in as many conditions as you want and if any of them are true, the test is skipped. In our case, we are using packaging.version.parse to allow us ...
Read now
Unlock full access