Registry / testing / pytest-astropy

pytest-astropy

JSON →
library0.11.0pypypi✓ verified 87d ago

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.

pip install pytest-astropy
INSTALL
IMPORT
SIG · PYTEST-ASTROPY
P
pytest-astropy
testingpythonv0.11.0
Install
6.5s avg
Import
426ms
Disk
109MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.454s · 108.8MB
glibc
py 3.103.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`.
fix
Upgrade 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.
fix
If 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.
fix
Migrate 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.
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.
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.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources