Registry / testing / pytest-regressions

pytest-regressions

JSON →
library2.11.0pypypi✓ verified 24d ago

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-regressions
INSTALL
IMPORT
SIG · PYTEST-REGRESSIONS
P
pytest-regressions
testingpythonv2.11.0
Install
2.9s avg
Import
Disk
33MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.11.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 33.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.9s · import 0.000s · 35MB
33MB installed
● package 33MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

data_regression
def test_data(data_regression): # No explicit import needed, pytest discovers fixtures automatically
pytest-regressions fixtures (e.g., `data_regression`, `file_regression`, `image_regression`) are automatically discovered by pytest. You do not need explicit `import` statements; just declare the fixture as an argument in your test function.

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.

import pytest def summary_grids(): # In a real scenario, this would compute/read values return { "Main Grid": { "id": 0, "cell_count": 1000, "active_cells": 300, "properties": [ {"name": "Temperature", "min": 75, "max": 85}, {"name": "Porosity", "min": 0.3, "max": 0.4}, ], }, } def test_grids_data(data_regression): data = summary_grids() data_regression.check(data)
Debug
Known issues
gotchaUsing the `--force-regen` or `--regen-all` pytest flags will regenerate and overwrite existing baseline files without failing the tests. While useful for updating baselines, misuse can lead to unintentional data loss if not carefully managed and committed to version control.
fix
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.
affects: All versions
gotchaSpecific regression fixtures like `dataframe_regression`, `image_regression`, `num_regression`, and `ndarrays_regression` rely on optional dependencies (pandas, Pillow, numpy) which are NOT installed automatically with `pip install pytest-regressions`. Attempting to use these fixtures without the respective dependencies will result in `ImportError` or similar issues.
fix
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.
affects: All versions
gotchaWhen using parametrized tests with regression fixtures, a separate regression file will be generated for each parameterization. This can lead to a large number of baseline files and potentially very long filenames if parameter names are extensive, which might exceed operating system path length limits.
fix
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.
affects: All versions
Upgrade
Version history
2.11.0latest on PyPI · released May 25, 2026
Audit
Dependencies
pytestrequiredCore testing framework that the plugin extends.
pytest-datadirrequiredManages the data directory for storing and retrieving regression baselines.
PyYAMLrequiredUsed for serialization/deserialization of YAML files by the data_regression fixture.
pandasoptionalRequired for the dataframe_regression fixture to handle pandas DataFrames.
PillowoptionalRequired for the image_regression fixture to handle image comparisons.
numpyoptionalRequired for the num_regression and ndarrays_regression fixtures to handle numeric data and arrays.
Agent activity
15 hits · last 30 days
node
14
Resources
pytest-regressions — pip install pytest-regressions · libregistry