Aug 20, 2019
It’s good practice to, as much as possible, write tests for your code. If you’re working with Python, pytest makes the process of writing and running tests much smoother. I wrote a few posts some time back on getting started with testing with pytest, so if you’re completely new to it, you might want to take a look at them:
- Getting started with pytest
- Asserting Exceptions with Pytest
- Capturing print statements while debugging
- Skipping tests
For testing CLI apps, Click provides a convenient module:
click.testing which has some useful functions (notably
CliRunner()) to help us invoke commands and check their behavior.
We’ll go ahead and test each part of our app - creating, reading, updating and deleting.