Testing code that should raise errors

Testing code that should raise errors#

Learning Objectives#

After working through this topic, you should be able to:

  • use tests to pin down desired behaviour of your functions

  • use pytest to check that expected errors are raised

  • explain why it is important to check that tests pass for the reasons that match your mental model of the code

Materials#

Video:

Download the slides.

Quiz#

Why is it important to test code that should raise errors?
It is important that tests pass for the resons we expect because:
What is the purpose of the `pytest.raises` block in a test case for code that should raise errors?