pytest-arraydiff
pytest plugin to help with comparing array output from tests
What it is and what it does
pytest-arraydiff is a pytest plugin that solves the problem of testing code that produces large numerical arrays—arrays too big to hard-code expected values directly in test assertions. Instead of writing `assert_allclose(result, [1, 2, 3])` for megabyte-sized outputs, you mark a test function with `@pytest.mark.array_compare`, have it return a numpy array or pandas DataFrame, and the plugin handles the rest. On first run, you generate reference files in your chosen format (plain text, FITS, or HDF5); on subsequent runs, the plugin compares new outputs to those references within configurable tolerances.
The plugin integrates directly into pytest's test discovery and reporting, so failures show side-by-side diffs of the generated and reference arrays. It's designed for scientific and data-heavy test suites where manual validation of large outputs is impractical, and where you want regression detection without maintaining brittle hard-coded assertions.
Use it for:
- Regression testing for numerical simulation or data processing pipelines that produce large arrays.
- Validating scientific code outputs (e.g., astronomy, physics, machine learning) against known-good reference data.
- Testing pandas DataFrame transformations by storing and comparing output DataFrames in HDF5 format.
- Detecting unintended changes in array-producing functions across refactors or dependency updates.
- Storing FITS format reference data for astronomical or imaging test suites using astropy.
- Comparing multi-dimensional numpy arrays with floating-point tolerance thresholds to avoid brittle exact-match tests.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that generates and compares numpy arrays (and related objects like pandas DataFrames) produced during tests against stored reference files, with support for text, FITS, and HDF5 formats.
Yes. This is a mature, actively maintained plugin (last release 73 days ago, no vulnerabilities) that solves a real problem in numerical testing. Install friction is minimal, the license is permissive, and it integrates seamlessly into pytest workflows. Recommended for any project with large array outputs that need regression testing.
Install
pytest-arraydiff on PyPI
pip
pip install pytest-arraydiffuv
uv add pytest-arraydiffpoetry
poetry add pytest-arraydiffInstalling pytest-arraydiff
Before you install
Low friction install with just pytest and numpy as runtime dependencies. The package is actively maintained with a recent release and no known vulnerabilities.
License in practice
BSD-3-Clause is a permissive license; you can use this package freely in commercial or private projects with minimal restrictions.
Quickstart
pip install pytest-arraydiff
import pytest
import numpy as np
@pytest.mark.array_compare
def test_succeeds():
return np.arange(3 * 5 * 4).reshape((3, 5, 4))
# Generate reference: py.test --arraydiff-generate-path=reference
# Compare against reference: py.test --arraydiff
Requires Python 3.9 or later; pytest and numpy must be installed.
Verify before relying
- Whether pandas and astropy are optional or required for HDF5 and FITS format support respectively.
- Performance characteristics when comparing very large arrays or many test files.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pytest, numpy |
| Maintenance | actively maintained — 73 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 344,276/month — #7,376 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_arraydiff-0.7.0-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
recursive-diffRecursively compares two Python data structures…
permissive · top 15,000 on PyPI
pytest-regressionsProvides pytest fixtures for writing regression…
permissive · top 5,000 on PyPI
pytest-filter-subpackageA pytest plugin that adds a `-P` option to run…
permissive · top 15,000 on PyPI
pytest-excelA pytest plugin that generates Excel reports…
permissive · top 15,000 on PyPI
pytest-progressA pytest plugin that displays real-time test…
permissive · top 15,000 on PyPI
pytest-astropyA meta-package that bundles pytest plugins and…
permissive · top 15,000 on PyPI
numpydanticNumpydantic adds type annotations and…
permissive · top 15,000 on PyPI
datacompyDataComPy compares two DataFrames across…
permissive · top 5,000 on PyPI
pyjsonCompares the similarity between two JSON files…
permissive · top 15,000 on PyPI
pytest-mplpytest-mpl is a pytest plugin that automates…
permissive · top 15,000 on PyPI