February 2022
Intermediate to advanced
274 pages
6h 28m
English
A test will fail if there is any uncaught exception. This can happen if
While any exception can fail a test, I prefer to use assert. In rare cases where assert is not suitable, use pytest.fail().
Here’s an example of using pytest’s fail() function to explicitly fail a test:
| | import pytest |
| | from cards import Card |
| | |
| | |
| | def test_with_fail(): |
| | c1 = Card("sit there", "brian") |
| | c2 = Card("do something", "okken") |
| | if c1 != c2: |
| | pytest.fail("they don't match") |
Here’s what the output looks like: ...
Read now
Unlock full access