February 2022
Intermediate to advanced
274 pages
6h 28m
English
When you write test functions, the normal Python assert statement is your primary tool to communicate test failure. The simplicity of this within pytest is brilliant. It’s what drives a lot of developers to use pytest over other frameworks.
If you’ve used any other testing framework, you’ve probably seen various assert helper functions. For example, following is a list of a few of the assert forms and assert helper functions from unittest:
pytest | unittest |
|---|---|
assert something | assertTrue(something) |
assert not something | assertFalse(something) |
assert a == b | assertEqual(a, b) |
assert a != b | assertNotEqual(a, b) |
assert a is None | assertIsNone(a) |
assert a is not None | assertIsNotNone(a) |
assert a <= b | assertLessEqual(a, b) |
… | … |
With pytest, you can ...