Install & Compatibility
Where this runs
tested against v0.11.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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.454s · 108.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 6.5s · import 0.397s · 105MB
109MB installed
● package 109MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pytest.mark.slow
✓ import pytest
@pytest.mark.slow
def test_something_slow(): ...
pytest-astropy enables this marker for CPU/memory intensive tests. Run with `--run-slow` or `-m slow`.
pytest.mark.hugemem
✓ import pytest
@pytest.mark.hugemem
def test_something_using_lots_of_memory(): ...
pytest-astropy enables this marker for CPU/memory intensive tests. Run with `--run-hugemem` or `-m hugemem`.
pytest.mark.remote_data
✓ import pytest
@pytest.mark.remote_data
def test_requires_internet(): ...
pytest-astropy, via pytest-remotedata, enables this marker for tests requiring internet data. Skipped by default; run with `--remote-data`.
pytest_configure (in conftest.py)
✓ from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
def pytest_configure(config):
config.option.astropy_header = True
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
Used in conftest.py to configure the test header provided by pytest-astropy-header.
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.
# conftest.py
import pytest
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
def pytest_configure(config):
config.option.astropy_header = True
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
# test_example.py
import pytest
@pytest.mark.slow
def test_a_slow_calculation():
"""This test simulates a slow operation."""
# Simulate a slow operation
sum(range(10**7))
assert True
@pytest.mark.remote_data
def test_fetch_remote_data():
"""This test requires remote data access."""
# Example: This test would typically try to fetch data from the internet.
# It will be skipped by default unless --remote-data is specified.
# import urllib.request
# with urllib.request.urlopen("https://www.google.com") as response:
# assert response.getcode() == 200
assert True # Placeholder for actual remote data logic
# To run the slow test:
# pytest --run-slow
# To run remote data tests:
# pytest --remote-data=any
Debug
Known issues
breakingSupport 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`.fixUpgrade Python to 3.7 or newer. Alternatively, use `pytest-astropy<0.9.0`.
affects: >=0.9.0
breakingThe `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.fixIf needed, explicitly `pip install pytest-openfiles` in your project's testing environment.
affects: >=0.11.0
deprecatedThe 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.fixMigrate from `packagename.test()` to direct `pytest` command-line invocations like `pytest --pyargs packagename`.
affects: Astropy >=8.0.0 (impacts usage of `pytest-astropy` in Astropy-affiliated projects)
gotchaWhen 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.fixUpdate `conftest.py` to `from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS` and remove any old `astropy.tests.pytest_plugins` imports.
affects: Astropy <4 (for projects upgrading to `pytest-astropy` and `pytest-astropy-header`)
Upgrade
Version history
0.11.0latest on PyPI · released Sep 26, 2023
Audit
Dependencies
pytestrequiredCore testing framework.
pytest-astropy-headerrequiredProvides custom test output header with diagnostic information.
pytest-remotedatarequiredControls execution of tests requiring remote data access.
pytest-doctestplusrequiredEnhances doctesting capabilities.
pytest-arraydiffrequiredEnables comparison of data arrays in tests.
pytest-filter-subpackagerequiredAdds a -P option to filter tests by sub-package.
pytest-mockrequiredProvides a wrapper around the mock package for use with pytest.
pytest-covrequiredMeasures test coverage.
hypothesisrequiredA Python library for property-based testing.