{"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":"python","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,"search_vec":"'0.6.1':52 'activ':60 'allow':33 'array':20,68 'arraydiff':2,5 'astropi':71 'avoid':24 'cadenc':61 'code':30 'compar':40 'comparison':16 'current':49 'data':19 'design':10 'diff':69 'everi':63 'exist':43 'facilit':12 'file':38 'generat':14,36 'hard':29 'hard-cod':28 'irregular':58 'larg':18 'month':65 'need':26 'numpi':70 'occur':55 'plugin':9 'produc':21 'pytest':1,4,8,66 'pytest-arraydiff':3 'refer':37,44 'releas':54 'result':41 'specifi':46 'test':23,34,67 'toler':47 'typic':62 'version':50 'within':45","created_at":"2026-04-15T18:44:36.703325+00:00","updated_at":"2026-04-16T19:55:49.549389+00:00","problems":[{"fix":"Add `arraydiff_base_dir = {rootdir}` (or your desired path) to your `pytest.ini` file:\n```ini\n[pytest]\narraydiff_base_dir = {rootdir}\n```","cause":"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.","error":"pytest.UsageError: arraydiff_base_dir is not set."},{"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.","cause":"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.","error":"AssertionError: Difference between actual and reference arrays exceeds tolerance."},{"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.","cause":"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.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'path/to/your/arraydiff_references/test_module/test_function_0.npy'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.7.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/astropy/pytest-arraydiff","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pytest-arraydiff/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}