The pytest Package

Prerequisite: Automated Testing

Reference:

Installation

If you are using Pip to manage software packages (recommended), install Pytest, as necessary:

pip install pytest

Otherwise, if you are using Pipenv, you will want to first navigate inside your repository's root directory before installing Pytest:

cd path/to/my-repo/
pipenv install pytest --dev # NOTE: the --dev flag denotes this package will be used in development only

Usage

The Pytest package is generally used as a command-line utility for running pre-defined files of "test" code. Follow the "Testing 1,2,3" Exercise to get acclimated with Pytest.

Example invocations:

Expecting Errors

The Pytest package can be imported to facilitate assertions that errors will be raised:

Fixtures

The Pytest package can be imported to facilitate the construction of test fixtures (for example, to be placed in the "conftest.py" file):

Last updated

Was this helpful?