Testing requirements.txt-Based Applications

A script or application may have dependencies—other projects that need to be installed before the script or application can run. A packaged project like Cards has a list of dependencies defined in either a pyproject.toml, setup.py, or setup.cfg file. Cards uses pyproject.toml. However, many projects don’t use packaging, and instead define dependencies in a requirements.txt file.

The dependency list in a requirements.txt file could be just a list of loose dependencies, like:

 typer
 requests

However, it’s more common for applications to “pin” dependencies by defining specific versions that are known to work:

 typer==0.3.2
 requests==2.26.0 ...

Get Python Testing with pytest now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.