pytest-regressions

2.10.0 · active · verified Mon Apr 13

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →