Python – Expect an exception using pytest

When you want to add a test to verify that an exception is raised, you can use pytest.raises() like this: When the code doesn’t raise an exception, you’ll see a test failed message like this: Example – Expect WordCounter to raise an exception I’m implementing the following WordCounter class using a test-driven approach. The first … Read more