February 2022
Intermediate to advanced
274 pages
6h 28m
English
In the last chapter, you got pytest up and running and saw how to run it against files and directories. In this chapter, you’ll learn how to write test functions in the context of testing a Python package. If you’re using pytest to test something other than a Python package, most of this chapter still applies.
We’re going to write tests for a simple task-tracking command-line application called Cards. We’ll look at how to use assert in tests, how tests handle unexpected exceptions, and how to test for expected exceptions.
Eventually, we’ll have a lot of tests. Therefore, we’ll look at how to organize tests into classes, modules, and directories.
Read now
Unlock full access