February 2022
Intermediate to advanced
274 pages
6h 28m
English
This is a test:
| | def test_passing(): |
| | assert (1, 2, 3) == (1, 2, 3) |
This looks very simple. It is. But there’s still a lot going on. The function test_passing() will be discovered by pytest as a test function because it starts with test_ and is in a file that starts with test_. And when the test is run, the assert statement will determine if the test passes or fails. assert is a keyword built into Python and has the behavior of raising a AssertionError exception if the expression after assert is false. Any uncaught exception raised within a test will cause the test to fail. Although any type of uncaught exception can cause a test to fail, traditionally we stick with AssertionError
Read now
Unlock full access