Registry / testing / pytest-arraydiff

pytest-arraydiff

JSON →
library0.7.0pypypi✓ verified 87d ago

pytest-arraydiff is a pytest plugin designed to facilitate the generation and comparison of large data arrays produced during tests, avoiding the need to hard-code them. It allows tests to generate reference files or compare results against existing references within specified tolerances. The current version is 0.6.1, with releases occurring on an irregular but active cadence, typically every few months.

pip install pytest-arraydiff
INSTALL
IMPORT
SIG · PYTEST-ARRAYDIFF
P
pytest-arraydiff
testingpythonv0.7.0
Install
4.6s avg
Import
424ms
Disk
102MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.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.920 runs
installs and imports cleanly · install 0.0s · import 0.450s · 102.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.6s · import 0.399s · 99MB
102MB installed
● package 102MB
Code
Verified usage

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

pytest
import pytest
The plugin's primary user interaction is via the `pytest.mark.array_compare` decorator, rather than direct imports of its own modules.

Mark a test function with `@pytest.mark.array_compare` and have it return the array to be compared. Run pytest with `--arraydiff-generate-path` to create reference files or without it to perform comparisons against existing reference data.

import pytest import numpy as np @pytest.mark.array_compare def test_succeeds(): # This test will generate or compare an array # run with `pytest --arraydiff-generate-path=reference_data` # or `pytest --arraydiff-default-format=text` return np.arange(3 * 5 * 4).reshape((3, 5, 4))
Debug
Known issues
breakingThe `astropy` library, previously a direct dependency for FITS format support, was removed as a hard requirement in v0.5.0. If you use the FITS format, you must now explicitly install `astropy` separately.
fix
Ensure `astropy` is installed if using the 'fits' file format: `pip install astropy`.
affects: >=0.5.0
gotchaWhen generating reference files using `--arraydiff-generate-path`, the created files are placed in the specified directory. These files should be manually reviewed for correctness and then moved to the designated 'reference' subdirectory relative to your test files.
fix
After generation, inspect the files and move them to `your_test_dir/reference/`.
affects: All
gotchaA test function decorated with `@pytest.mark.array_compare` must return the NumPy array (or other supported object like a pandas DataFrame) that is intended for comparison. If nothing is returned, the array comparison functionality will not be invoked.
fix
Ensure your marked test function explicitly `return`s the array you want to compare.
affects: All
gotchaThe default file format for comparison is 'text'. If you intend to use another format like 'fits' or 'pandas_hdf5', you must specify it either via the `file_format` argument in the decorator (`@pytest.mark.array_compare(file_format='fits')`) or using the `--arraydiff-default-format` command-line option (`pytest --arraydiff-default-format=fits`).
fix
Explicitly set the desired `file_format` for non-text comparisons.
affects: All
Errors
Common errors & fixes
pytest.UsageError: arraydiff_base_dir is not set.
The `pytest-arraydiff` plugin requires the `arraydiff_base_dir` configuration option to be explicitly set in your `pytest.ini` or `conftest.py` file, especially when using reference files.
fix
Add `arraydiff_base_dir = {rootdir}` (or your desired path) to your `pytest.ini` file:
```ini
[pytest]
arraydiff_base_dir = {rootdir}
```
AssertionError: Difference between actual and reference arrays exceeds tolerance.
The NumPy array produced by the test function does not match the stored reference array within the configured absolute (`arraydiff_tolerance_abs`) and/or relative (`arraydiff_tolerance_rel`) tolerances.
fix
Either update the reference array by running pytest with the `--arraydiff-generate-references` flag, adjust the test logic to produce the expected array, or modify the `arraydiff_tolerance_abs` and `arraydiff_tolerance_rel` settings in your `pytest.ini` or using the `pytest.mark.array_diff` decorator.
FileNotFoundError: [Errno 2] No such file or directory: 'path/to/your/arraydiff_references/test_module/test_function_0.npy'
The test is configured to compare an array against a reference file, but the expected reference file does not exist at the specified path, and pytest is not currently running in reference generation mode.
fix
Generate the missing reference file by running `pytest --arraydiff-generate-references`. Ensure that `arraydiff_base_dir` and any other reference path configurations in `pytest.ini` or `conftest.py` are correct.
Upgrade
Version history
0.7.0latest on PyPI · released Jun 2, 2026
Audit
Dependencies
pytestrequiredCore testing framework that this plugin extends.
numpyrequiredRequired for array manipulation and comparison functions.
astropyoptionalRequired for 'fits' file format support, but is an optional dependency since v0.5.0.
pandasoptionalRequired for 'pandas_hdf5' file format support.
Agent activity
6 hits · last 30 days
node
6
Resources
pytest-arraydiff — pip install pytest-arraydiff · libregistry