skillfed

pytest-arraydiff

pytest plugin to help with comparing array output from tests

pytest-arraydiff v0.7.0 344.3K downloads/30d#7,376 on PyPI27
Permissive license BSD-3-Clause Active released

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-arraydiff

uv

uv add pytest-arraydiff

poetry

poetry add pytest-arraydiff

Installing 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

Development Status :: 4 - BetaFramework :: PytestIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development :: TestingTopic :: Utilities

Tags

pytest array comparison testingnumpy array regression testingtest output array validationpytest reference file generationarray diff testing pluginnumpy test fixtureslarge array test comparison
numpy-testingregression-testingscientific-computing

More Utilities packages