1# Licensed under a 3-clause BSD style license - see LICENSE.rst 2 3# This file is the main file used when running tests with pytest directly, 4# in particular if running e.g. ``pytest docs/``. 5 6import os 7import tempfile 8 9import hypothesis 10 11from astropy import __version__ 12 13try: 14 from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS 15except ImportError: 16 PYTEST_HEADER_MODULES = {} 17 TESTED_VERSIONS = {} 18 19 20# This has to be in the root dir or it will not display in CI. 21def pytest_configure(config): 22 PYTEST_HEADER_MODULES['PyERFA'] = 'erfa' 23 PYTEST_HEADER_MODULES['Cython'] = 'cython' 24 PYTEST_HEADER_MODULES['Scikit-image'] = 'skimage' 25 PYTEST_HEADER_MODULES['asdf'] = 'asdf' 26 PYTEST_HEADER_MODULES['pyarrow'] = 'pyarrow' 27 TESTED_VERSIONS['Astropy'] = __version__ 28 29 30# This has to be in the root dir or it will not display in CI. 31def pytest_report_header(config): 32 # This gets added after the pytest-astropy-header output. 33 return (f'ARCH_ON_CI: {os.environ.get("ARCH_ON_CI", "undefined")}\n' 34 f'IS_CRON: {os.environ.get("IS_CRON", "undefined")}\n') 35 36 37# Tell Hypothesis that we might be running slow tests, to print the seed blob 38# so we can easily reproduce failures from CI, and derive a fuzzing profile 39# to try many more inputs when we detect a scheduled build or when specifically 40# requested using the HYPOTHESIS_PROFILE=fuzz environment variable or 41# `pytest --hypothesis-profile=fuzz ...` argument. 42 43hypothesis.settings.register_profile( 44 'ci', deadline=None, print_blob=True, derandomize=True 45) 46hypothesis.settings.register_profile( 47 'fuzzing', deadline=None, print_blob=True, max_examples=1000 48) 49default = 'fuzzing' if (os.environ.get('IS_CRON') == 'true' and os.environ.get('ARCH_ON_CI') not in ('aarch64', 'ppc64le')) else 'ci' # noqa: E501 50hypothesis.settings.load_profile(os.environ.get('HYPOTHESIS_PROFILE', default)) 51 52# Make sure we use temporary directories for the config and cache 53# so that the tests are insensitive to local configuration. 54 55os.environ['XDG_CONFIG_HOME'] = tempfile.mkdtemp('astropy_config') 56os.environ['XDG_CACHE_HOME'] = tempfile.mkdtemp('astropy_cache') 57 58os.mkdir(os.path.join(os.environ['XDG_CONFIG_HOME'], 'astropy')) 59os.mkdir(os.path.join(os.environ['XDG_CACHE_HOME'], 'astropy')) 60 61# Note that we don't need to change the environment variables back or remove 62# them after testing, because they are only changed for the duration of the 63# Python process, and this configuration only matters if running pytest 64# directly, not from e.g. an IPython session. 65