{"id":6825,"library":"pytest-arraydiff","title":"Pytest ArrayDiff","description":"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.","status":"active","version":"0.6.1","language":"en","source_language":"en","source_url":"https://github.com/astropy/pytest-arraydiff","tags":["pytest","testing","array","diff","numpy","astropy"],"install":[{"cmd":"pip install pytest-arraydiff","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core testing framework that this plugin extends.","package":"pytest","optional":false},{"reason":"Required for array manipulation and comparison functions.","package":"numpy","optional":false},{"reason":"Required for 'fits' file format support, but is an optional dependency since v0.5.0.","package":"astropy","optional":true},{"reason":"Required for 'pandas_hdf5' file format support.","package":"pandas","optional":true}],"imports":[{"note":"The plugin's primary user interaction is via the `pytest.mark.array_compare` decorator, rather than direct imports of its own modules.","symbol":"pytest","correct":"import pytest"}],"quickstart":{"code":"import pytest\nimport numpy as np\n\n@pytest.mark.array_compare\ndef test_succeeds():\n    # This test will generate or compare an array\n    # run with `pytest --arraydiff-generate-path=reference_data`\n    # or `pytest --arraydiff-default-format=text`\n    return np.arange(3 * 5 * 4).reshape((3, 5, 4))","lang":"python","description":"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."},"warnings":[{"fix":"Ensure `astropy` is installed if using the 'fits' file format: `pip install astropy`.","message":"The `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.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"After generation, inspect the files and move them to `your_test_dir/reference/`.","message":"When 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your marked test function explicitly `return`s the array you want to compare.","message":"A 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Explicitly set the desired `file_format` for non-text comparisons.","message":"The 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`).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}