pytest-regressions is a Pytest plugin that provides a set of fixtures to simplify writing regression tests. It helps in maintaining tests that generate substantial or specific data files, such as dictionaries, dataframes, images, or numeric tables. The plugin stores expected data as baselines in a data directory (leveraging pytest-datadir) and compares future test runs against these baselines, providing detailed diffs upon failure. The current version is 2.10.0, and it maintains a regular release cadence with frequent minor updates.
pip install pytest-regressionsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates using the `data_regression` fixture to test a dictionary output. The first run with this test will generate a `test_grids_data.yml` file in the automatically created `data` directory (or a custom one if configured). Subsequent runs will compare the output of `summary_grids()` against the contents of this YAML file. If they differ, the test fails with a detailed diff.
Only use `--force-regen` or `--regen-all` when intentionally updating baselines. Always review the changes to the generated files before committing them to version control.
Install the required optional dependencies manually, e.g., `pip install pytest-regressions[dataframe]` or `pip install pandas Pillow numpy` depending on the fixtures you intend to use.
Be mindful of parameter naming in parametrized tests to keep filenames concise. Consider using custom `basename` arguments for fixtures if default naming creates issues, or overriding `pytest-datadir` fixtures for more controlled path generation.