Track 13 · Lesson 4 of 12
Testing exceptions and floats
Check that code raises the right exception with pytest.raises, and compare floating-point results safely with pytest.approx.
You will be able to
- Test that a function raises a specific exception with pytest.raises
- Check the exception's message with match= or excinfo.value
- Explain why == is unreliable for floats and use pytest.approx instead
- Choose between rounding, approx with rel or abs, and exact comparison
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.