{"id":5434,"library":"pytest-regressions","title":"pytest-regressions","description":"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.","status":"active","version":"2.10.0","language":"en","source_language":"en","source_url":"https://github.com/ESSS/pytest-regressions","tags":["pytest","testing","regression testing","fixtures","data validation","snapshot testing","test automation"],"install":[{"cmd":"pip install pytest-regressions","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework that the plugin extends.","package":"pytest","optional":false},{"reason":"Manages the data directory for storing and retrieving regression baselines.","package":"pytest-datadir","optional":false},{"reason":"Used for serialization/deserialization of YAML files by the data_regression fixture.","package":"PyYAML","optional":false},{"reason":"Required for the dataframe_regression fixture to handle pandas DataFrames.","package":"pandas","optional":true},{"reason":"Required for the image_regression fixture to handle image comparisons.","package":"Pillow","optional":true},{"reason":"Required for the num_regression and ndarrays_regression fixtures to handle numeric data and arrays.","package":"numpy","optional":true}],"imports":[{"note":"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.","symbol":"data_regression","correct":"def test_data(data_regression):\n    # No explicit import needed, pytest discovers fixtures automatically"}],"quickstart":{"code":"import pytest\n\ndef summary_grids():\n    # In a real scenario, this would compute/read values\n    return {\n        \"Main Grid\": {\n            \"id\": 0,\n            \"cell_count\": 1000,\n            \"active_cells\": 300,\n            \"properties\": [\n                {\"name\": \"Temperature\", \"min\": 75, \"max\": 85},\n                {\"name\": \"Porosity\", \"min\": 0.3, \"max\": 0.4},\n            ],\n        },\n    }\n\ndef test_grids_data(data_regression):\n    data = summary_grids()\n    data_regression.check(data)","lang":"python","description":"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."},"warnings":[{"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.","message":"Using 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Specific 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}