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-arraydiffVerified import paths — ran on the pinned version, not inferred.
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.
Ensure `astropy` is installed if using the 'fits' file format: `pip install astropy`.
After generation, inspect the files and move them to `your_test_dir/reference/`.
Ensure your marked test function explicitly `return`s the array you want to compare.
Explicitly set the desired `file_format` for non-text comparisons.
Add `arraydiff_base_dir = {rootdir}` (or your desired path) to your `pytest.ini` file:
```ini
[pytest]
arraydiff_base_dir = {rootdir}
```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.
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.