{"id":6827,"library":"pytest-astropy","title":"pytest-astropy","description":"pytest-astropy is a meta-package that consolidates and provides testing dependencies and various pytest plugins used by the Astropy Project and its affiliated packages. It aims to simplify test setup for projects within the Astropy ecosystem and can also be used by other Python projects. The library is actively maintained, with its current version being 0.11.0, and receives regular updates.","status":"active","version":"0.11.0","language":"en","source_language":"en","source_url":"https://github.com/astropy/pytest-astropy","tags":["pytest","astropy","testing","plugins","astronomy"],"install":[{"cmd":"pip install pytest-astropy","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core testing framework.","package":"pytest","optional":false},{"reason":"Provides custom test output header with diagnostic information.","package":"pytest-astropy-header","optional":false},{"reason":"Controls execution of tests requiring remote data access.","package":"pytest-remotedata","optional":false},{"reason":"Enhances doctesting capabilities.","package":"pytest-doctestplus","optional":false},{"reason":"Enables comparison of data arrays in tests.","package":"pytest-arraydiff","optional":false},{"reason":"Adds a -P option to filter tests by sub-package.","package":"pytest-filter-subpackage","optional":false},{"reason":"Provides a wrapper around the mock package for use with pytest.","package":"pytest-mock","optional":false},{"reason":"Measures test coverage.","package":"pytest-cov","optional":false},{"reason":"A Python library for property-based testing.","package":"hypothesis","optional":false}],"imports":[{"note":"pytest-astropy enables this marker for CPU/memory intensive tests. Run with `--run-slow` or `-m slow`.","symbol":"pytest.mark.slow","correct":"import pytest\n@pytest.mark.slow\ndef test_something_slow(): ..."},{"note":"pytest-astropy enables this marker for CPU/memory intensive tests. Run with `--run-hugemem` or `-m hugemem`.","symbol":"pytest.mark.hugemem","correct":"import pytest\n@pytest.mark.hugemem\ndef test_something_using_lots_of_memory(): ..."},{"note":"pytest-astropy, via pytest-remotedata, enables this marker for tests requiring internet data. Skipped by default; run with `--remote-data`.","symbol":"pytest.mark.remote_data","correct":"import pytest\n@pytest.mark.remote_data\ndef test_requires_internet(): ..."},{"note":"Used in conftest.py to configure the test header provided by pytest-astropy-header.","symbol":"pytest_configure (in conftest.py)","correct":"from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS\ndef pytest_configure(config):\n    config.option.astropy_header = True\n    PYTEST_HEADER_MODULES['Astropy'] = 'astropy'"}],"quickstart":{"code":"# conftest.py\nimport pytest\nfrom pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS\n\ndef pytest_configure(config):\n    config.option.astropy_header = True\n    PYTEST_HEADER_MODULES['Astropy'] = 'astropy'\n\n# test_example.py\nimport pytest\n\n@pytest.mark.slow\ndef test_a_slow_calculation():\n    \"\"\"This test simulates a slow operation.\"\"\"\n    # Simulate a slow operation\n    sum(range(10**7))\n    assert True\n\n@pytest.mark.remote_data\ndef test_fetch_remote_data():\n    \"\"\"This test requires remote data access.\"\"\"\n    # Example: This test would typically try to fetch data from the internet.\n    # It will be skipped by default unless --remote-data is specified.\n    # import urllib.request\n    # with urllib.request.urlopen(\"https://www.google.com\") as response:\n    #     assert response.getcode() == 200\n    assert True # Placeholder for actual remote data logic\n\n# To run the slow test:\n# pytest --run-slow\n\n# To run remote data tests:\n# pytest --remote-data=any","lang":"python","description":"To quickly get started, create a `conftest.py` file in your project's root or test directory to configure the Astropy test header. Then, define tests using markers like `pytest.mark.slow` for computationally intensive tests or `pytest.mark.remote_data` for tests requiring internet access. These markers are enabled by the plugins within `pytest-astropy`. Slow and remote data tests are skipped by default and require specific command-line flags to be run."},"warnings":[{"fix":"Upgrade Python to 3.7 or newer. Alternatively, use `pytest-astropy<0.9.0`.","message":"Support for Python 3.6 was dropped in `pytest-astropy` version 0.9.0. Projects using older Python versions will need to upgrade their environment or pin an earlier version of `pytest-astropy`.","severity":"breaking","affected_versions":">=0.9.0"},{"fix":"If needed, explicitly `pip install pytest-openfiles` in your project's testing environment.","message":"The `pytest-openfiles` plugin was dropped from `pytest-astropy` in version 0.11.0. If your project explicitly relied on `pytest-openfiles` being pulled in via `pytest-astropy`, you will need to install it directly.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Migrate from `packagename.test()` to direct `pytest` command-line invocations like `pytest --pyargs packagename`.","message":"The Astropy `astropy.test()`, `TestRunner`, and `TestRunnerBase` APIs are deprecated as of Astropy v8.0. This change affects downstream packages that generate `packagename.test` functions using `TestRunner`. It is recommended to switch to using `pytest` natively (e.g., `pytest --pyargs packagename`) instead of `packagename.test()` functions.","severity":"deprecated","affected_versions":"Astropy >=8.0.0 (impacts usage of `pytest-astropy` in Astropy-affiliated projects)"},{"fix":"Update `conftest.py` to `from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS` and remove any old `astropy.tests.pytest_plugins` imports.","message":"When migrating older Astropy-affiliated packages, ensure that any `astropy.tests.plugins.display` imports in your `conftest.py` are updated to use `pytest_astropy_header.display`. Older plugin paths are no longer supported by `pytest-astropy-header` for Astropy versions less than 4.","severity":"gotcha","affected_versions":"Astropy <4 (for projects upgrading to `pytest-astropy` and `pytest-astropy-header`)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}