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

Python – Make an HTTP request and use the returned JSON

In Python the requests module makes it simple to make HTTP requests and handle the returned JSON. I have a web API that returns exchange rates for a given currency. In this article, I’ll show how to use the requests module to call this endpoint and use the returned JSON. This will include error handling, … Read more