Testing a Package

We’ll use the sample project, Tasks, as discussed in The Tasks Project, to see how to write test functions for a Python package. Tasks is a Python package that includes a command-line tool of the same name, tasks.

Appendix 4, Packaging and Distributing Python Projects includes an explanation of how to distribute your projects locally within a small team or globally through PyPI, so I won’t go into detail of how to do that here; however, let’s take a quick look at what’s in the Tasks project and how the different files fit into the story of testing this project.

Following is the file structure for the Tasks project:

 tasks_proj/
 ├── CHANGELOG.rst
 ├── LICENSE
 ├── MANIFEST.in
 ├── README.rst
 ├── setup.py
 ├── src
 │   ...

Get Python Testing with pytest now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.