pytest-astropy-header
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
- breaking The header plugin was moved from `astropy.tests.plugins.display` to `pytest_astropy_header` as a standalone package. If your `conftest.py` or other test configuration still uses the old `astropy` import path, it will break when upgrading to Astropy v4.0+ or newer versions of `pytest-astropy-header`.
- gotcha `pytest-astropy-header` explicitly does not support `astropy < 4`. Using it with older Astropy versions may lead to unexpected behavior or errors.
- gotcha Customizing the modules and versions displayed in the header requires direct modification of `PYTEST_HEADER_MODULES` and `TESTED_VERSIONS` dictionaries within your `conftest.py`'s `pytest_configure` hook. Incorrect keys or values, or attempting to modify them outside this hook, may not yield the desired header output.
Install
-
pip install pytest-astropy-header
Imports
- PYTEST_HEADER_MODULES, TESTED_VERSIONS
from astropy.tests.plugins.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
Quickstart
# 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