pytest-astropy-header

0.2.2 · active · verified Wed Apr 15

This pytest plugin provides a way to include diagnostic information about the system, Python installation, and select dependencies in the header of the test output. It is primarily optimized for use with Astropy-related projects but is designed to be usable with any package. The current version is 0.2.2, with releases typically tied to the needs and development cycle of the Astropy project.

Warnings

Install

Imports

Quickstart

To enable and customize `pytest-astropy-header`, you typically place configuration in your project's `conftest.py` file. The plugin automatically registers when installed, but explicit configuration in `pytest_configure` ensures robust activation and allows for customization of the displayed package versions and modules.

# conftest.py in your project's root or test directory

import os
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS

def pytest_configure(config):
    # Ensure the astropy header is enabled
    config.option.astropy_header = True

    # Customize modules shown in the header
    # Example: Remove 'Pandas' from default, add 'scikit-image'
    # The key is the display name, value is the module import name
    if 'Pandas' in PYTEST_HEADER_MODULES:
        PYTEST_HEADER_MODULES.pop('Pandas')
    PYTEST_HEADER_MODULES['Scikit-image'] = 'skimage'

    # Customize package versions shown in the header
    # For a hypothetical 'mypackage' (replace with your package's actual import)
    try:
        import mypackage
        TESTED_VERSIONS['mypackage'] = mypackage.__version__
    except ImportError:
        TESTED_VERSIONS['mypackage'] = 'not installed'

# To run tests and see the header, simply execute pytest from your terminal:
# pytest

view raw JSON →