try: import matplotlib except ImportError: HAS_MATPLOTLIB = False else: HAS_MATPLOTLIB = True enable_deprecations_as_exceptions( include_astropy_deprecations=False, # This is a workaround for the OpenSSL deprecation warning that comes from # the `requests` module. It only appears when both asdf and sphinx are # installed. This can be removed once pyopenssl 1.7.20+ is released. modules_to_ignore_on_import=['requests'], warnings_to_ignore_by_pyver={ # This warning shows up in mpl <3.1.2 on python 3.8, # remove once 3.1.2 is released (3, 8): set([ (r"In future, it will be an error for 'np.bool_' scalars " "to be interpreted as an index", DeprecationWarning), ]) }) if HAS_MATPLOTLIB: matplotlib.use('Agg') matplotlibrc_cache = {} def pytest_configure(config):
# this contains imports plugins that configure py.test for astropy tests. # by importing them here in conftest.py they are discoverable by py.test # no matter how it is invoked within the source tree. from importlib.util import find_spec from astropy.version import version as astropy_version from astropy.tests.plugins.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS from astropy.tests.helper import enable_deprecations_as_exceptions ## Uncomment the following line to treat all DeprecationWarnings as ## exceptions enable_deprecations_as_exceptions() # Uncomment and customize the following lines to add/remove entries from # the list of packages for which version numbers are displayed when running # the tests. Making it pass for KeyError is essential in some cases when # the package uses other astropy affiliated packages. try: PYTEST_HEADER_MODULES['Astropy'] = 'astropy' PYTEST_HEADER_MODULES['gwcs'] = 'gwcs' del PYTEST_HEADER_MODULES['h5py'] del PYTEST_HEADER_MODULES['Pandas'] del PYTEST_HEADER_MODULES['Matplotlib'] except (NameError, KeyError): # NameError is needed to support Astropy < 1.0 pass # Use ASDF schema tester plugin if ASDF is installed if find_spec('asdf') is not None: PYTEST_HEADER_MODULES['Asdf'] = 'asdf'
# this contains imports plugins that configure py.test for astropy tests. # by importing them here in conftest.py they are discoverable by py.test # no matter how it is invoked within the source tree. import os from astropy.tests.helper import enable_deprecations_as_exceptions from astropy.tests.plugins.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS # Uncomment the following line to treat all DeprecationWarnings as # exceptions enable_deprecations_as_exceptions() # Uncomment and customize the following lines to add/remove entries from # the list of packages for which version numbers are displayed when running # the tests. Making it pass for KeyError is essential in some cases when # the package uses other astropy affiliated packages. PYTEST_HEADER_MODULES['Astropy'] = 'astropy' PYTEST_HEADER_MODULES['scikit-image'] = 'skimage' del PYTEST_HEADER_MODULES['h5py'] # Uncomment the following lines to display the version number of the # package rather than the version number of Astropy in the top line when # running the tests. # This is to figure out the affiliated package version, rather than # using Astropy's try: from .version import version except ImportError: version = 'dev'
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): # The above checks whether we are running in a PyInstaller bundle. warnings.filterwarnings("ignore", "(?s).*MATPLOTLIBDATA.*", category=UserWarning) # Note: while the filterwarnings is required, this import has to come after the # filterwarnings above, because this attempts to import matplotlib: from astropy.utils.compat.optional_deps import HAS_MATPLOTLIB if HAS_MATPLOTLIB: import matplotlib enable_deprecations_as_exceptions( include_astropy_deprecations=False, # This is a workaround for the OpenSSL deprecation warning that comes from # the `requests` module. It only appears when both asdf and sphinx are # installed. This can be removed once pyopenssl 1.7.20+ is released. modules_to_ignore_on_import=['requests']) matplotlibrc_cache = {} @pytest.fixture def ignore_matplotlibrc(): # This is a fixture for tests that use matplotlib but not pytest-mpl # (which already handles rcParams) from matplotlib import pyplot as plt with plt.style.context({}, after_reset=True): yield
try: import matplotlib except ImportError: HAS_MATPLOTLIB = False else: HAS_MATPLOTLIB = True if find_spec('asdf') is not None: from asdf import __version__ as asdf_version if asdf_version >= '2.0.0': pytest_plugins = ['asdf.tests.schema_tester'] PYTEST_HEADER_MODULES['Asdf'] = 'asdf' enable_deprecations_as_exceptions( include_astropy_deprecations=False, # This is a workaround for the OpenSSL deprecation warning that comes from # the `requests` module. It only appears when both asdf and sphinx are # installed. This can be removed once pyopenssl 1.7.20+ is released. modules_to_ignore_on_import=['requests']) if HAS_MATPLOTLIB: matplotlib.use('Agg') matplotlibrc_cache = {} def pytest_configure(config): builtins._pytest_running = True # do not assign to matplotlibrc_cache in function scope if HAS_MATPLOTLIB: matplotlibrc_cache.update(matplotlib.rcParams) matplotlib.rcdefaults()
try: PYTEST_HEADER_MODULES['Astropy'] = 'astropy' PYTEST_HEADER_MODULES['APLpy'] = 'aplpy' PYTEST_HEADER_MODULES['pyregion'] = 'pyregion' PYTEST_HEADER_MODULES['pyVO'] = 'pyvo' # keyring doesn't provide __version__ any more # PYTEST_HEADER_MODULES['keyring'] = 'keyring' del PYTEST_HEADER_MODULES['h5py'] del PYTEST_HEADER_MODULES['Scipy'] del PYTEST_HEADER_MODULES['Pandas'] except (NameError, KeyError): pass # ignoring pyvo can be removed once we require >0.9.3 enable_deprecations_as_exceptions( include_astropy_deprecations=False, warnings_to_ignore_entire_module=['pyregion'], modules_to_ignore_on_import=['pyvo']) # add '_testrun' to the version name so that the user-agent indicates that # it's being run in a test from . import version version.version += '_testrun' # This is to figure out the affiliated package version, rather than # using Astropy's from .version import version, astropy_helpers_version packagename = os.path.basename(os.path.dirname(__file__)) TESTED_VERSIONS[packagename] = version TESTED_VERSIONS['astropy_helpers'] = astropy_helpers_version
try: from pytest_astropy_header.display import (PYTEST_HEADER_MODULES, TESTED_VERSIONS) except ImportError: PYTEST_HEADER_MODULES = {} TESTED_VERSIONS = {} try: from acstools.version import version except ImportError: version = 'unknown' # Uncomment the following line to treat all DeprecationWarnings as # exceptions # NOTE: socks warning fixed by https://github.com/Anorov/PySocks/pull/106 # but not released yet. from astropy.tests.helper import enable_deprecations_as_exceptions enable_deprecations_as_exceptions(warnings_to_ignore_entire_module=['socks']) # Uncomment and customize the following lines to add/remove entries # from the list of packages for which version numbers are displayed # when running the tests. PYTEST_HEADER_MODULES['Astropy'] = 'astropy' PYTEST_HEADER_MODULES['beautifulsoup4'] = 'bs4' PYTEST_HEADER_MODULES['requests'] = 'requests' PYTEST_HEADER_MODULES['stsci.tools'] = 'stsci.tools' PYTEST_HEADER_MODULES.pop('Pandas') PYTEST_HEADER_MODULES.pop('h5py') TESTED_VERSIONS['acstools'] = version
import astropy.version from astropy.tests.helper import enable_deprecations_as_exceptions if astropy.version.version < "3.0": # With older versions of Astropy, we actually need to import the pytest # plugins themselves in order to make them discoverable by pytest. from astropy.tests.pytest_plugins import * else: # As of Astropy 3.0, the pytest plugins provided by Astropy are # automatically made available when Astropy is installed. This means it's # not necessary to import them here, but we still need to import global # variables that are used for configuration. from astropy.tests.plugins.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS # TODO: add numpy again once https://github.com/astropy/regions/pull/252 is addressed enable_deprecations_as_exceptions( warnings_to_ignore_entire_module=["numpy", "astropy"]) # Declare for which packages version numbers should be displayed # when running the tests PYTEST_HEADER_MODULES["cython"] = "cython" PYTEST_HEADER_MODULES["uncertainties"] = "uncertainties" PYTEST_HEADER_MODULES["iminuit"] = "iminuit" PYTEST_HEADER_MODULES["astropy"] = "astropy" PYTEST_HEADER_MODULES["regions"] = "regions" PYTEST_HEADER_MODULES["healpy"] = "healpy" PYTEST_HEADER_MODULES["sherpa"] = "sherpa" PYTEST_HEADER_MODULES["gammapy"] = "gammapy" PYTEST_HEADER_MODULES["naima"] = "naima" PYTEST_HEADER_MODULES["reproject"] = "reproject"
from astropy.tests.helper import enable_deprecations_as_exceptions # Uncomment the following line to treat all DeprecationWarnings as # exceptions. For Astropy v2.0 or later, there are 2 additional keywords, # as follow (although default should work for most cases). # To ignore some packages that produce deprecation warnings on import # (in addition to 'compiler', 'scipy', 'pygments', 'ipykernel', and # 'setuptools'), add: # modules_to_ignore_on_import=['module_1', 'module_2'] # To ignore some specific deprecation warning messages for Python version # MAJOR.MINOR or later, add: # warnings_to_ignore_by_pyver={(MAJOR, MINOR): ['Message to ignore']} from distutils.version import LooseVersion if LooseVersion(astropy_version) < LooseVersion('2.0'): enable_deprecations_as_exceptions() else: enable_deprecations_as_exceptions(warnings_to_ignore_entire_module=['astropy.io.fits']) # Uncomment and customize the following lines to add/remove entries from # the list of packages for which version numbers are displayed when running # the tests. Making it pass for KeyError is essential in some cases when # the package uses other astropy affiliated packages. try: PYTEST_HEADER_MODULES['Astropy'] = 'astropy' PYTEST_HEADER_MODULES['astropy-healpix'] = 'astropy_healpix' PYTEST_HEADER_MODULES['Cython'] = 'cython' del PYTEST_HEADER_MODULES['h5py'] del PYTEST_HEADER_MODULES['Matplotlib'] except (NameError, KeyError): # NameError is needed to support Astropy < 1.0 pass
# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This file contains pytest configuration settings that are astropy-specific (i.e. those that would not necessarily be shared by affiliated packages making use of astropy's test runner). """ from astropy.tests.plugins.display import PYTEST_HEADER_MODULES from astropy.tests.helper import enable_deprecations_as_exceptions enable_deprecations_as_exceptions(include_astropy_deprecations=False) try: import matplotlib except ImportError: pass else: matplotlib.use('Agg') # This is astropy-specific so should not be included in a generic plugin that # could potentially be used by other projects PYTEST_HEADER_MODULES['Cython'] = 'cython'
try: PYTEST_HEADER_MODULES['Astropy'] = 'astropy' PYTEST_HEADER_MODULES['APLpy'] = 'aplpy' PYTEST_HEADER_MODULES['pyregion'] = 'pyregion' PYTEST_HEADER_MODULES['pyVO'] = 'pyvo' # keyring doesn't provide __version__ any more # PYTEST_HEADER_MODULES['keyring'] = 'keyring' del PYTEST_HEADER_MODULES['h5py'] del PYTEST_HEADER_MODULES['Scipy'] del PYTEST_HEADER_MODULES['Pandas'] except (NameError, KeyError): pass # ignoring pyvo can be removed once we require >0.9.3 enable_deprecations_as_exceptions( include_astropy_deprecations=False, warnings_to_ignore_entire_module=['pyregion', 'html5lib'], ) # add '_testrun' to the version name so that the user-agent indicates that # it's being run in a test from . import version version.version += '_testrun' # This is to figure out the affiliated package version, rather than # using Astropy's from .version import version, astropy_helpers_version packagename = os.path.basename(os.path.dirname(__file__)) TESTED_VERSIONS[packagename] = version TESTED_VERSIONS['astropy_helpers'] = astropy_helpers_version
else: # As of Astropy 3.0, the pytest plugins provided by Astropy are # automatically made available when Astropy is installed. This means it's # not necessary to import them here, but we still need to import global # variables that are used for configuration. from astropy.tests.plugins.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS packagename = os.path.basename(os.path.dirname(__file__)) TESTED_VERSIONS[packagename] = version.version # Treat all DeprecationWarnings as exceptions from astropy.tests.helper import enable_deprecations_as_exceptions # TODO: add numpy again once https://github.com/astropy/regions/pull/252 is addressed enable_deprecations_as_exceptions(warnings_to_ignore_entire_module=["numpy", "astropy"]) # Declare for which packages version numbers should be displayed # when running the tests PYTEST_HEADER_MODULES["cython"] = "cython" PYTEST_HEADER_MODULES["uncertainties"] = "uncertainties" PYTEST_HEADER_MODULES["iminuit"] = "iminuit" PYTEST_HEADER_MODULES["astropy"] = "astropy" PYTEST_HEADER_MODULES["regions"] = "regions" PYTEST_HEADER_MODULES["healpy"] = "healpy" PYTEST_HEADER_MODULES["sherpa"] = "sherpa" PYTEST_HEADER_MODULES["gammapy"] = "gammapy" PYTEST_HEADER_MODULES["naima"] = "naima" PYTEST_HEADER_MODULES["reproject"] = "reproject"
"""Custom ``pytest`` configurations.""" from astropy.tests.helper import enable_deprecations_as_exceptions # Turn deprecation warnings into exceptions. # NOTE: socks warning fixed by https://github.com/Anorov/PySocks/pull/106 # but not released yet. enable_deprecations_as_exceptions(warnings_to_ignore_entire_module=['socks']) # Require these pytest plugins to run. pytest_plugins = ["pytest_ciwatson"] # For easy inspection on what dependencies were used in test. def pytest_report_header(config): import sys import warnings from astropy.utils.introspection import resolve_name s = "\nFull Python Version: \n{0}\n\n".format(sys.version) for module_name in ('numpy', 'astropy', 'scipy', 'matplotlib', 'stsci.tools'): try: with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) module = resolve_name(module_name) except ImportError: s += "{0}: not available\n".format(module_name) else: try: