pytest-astropy

0.11.0 · active · verified Wed Apr 15

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.

Warnings

Install

Imports

Quickstart

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

view raw JSON →