|
1 | | -# Licensed under a 3-clause BSD style license - see LICENSE.rst |
2 | | -import os |
3 | | -from distutils.version import LooseVersion |
4 | | -# this contains imports plugins that configure py.test for astropy tests. |
5 | | -# by importing them here in conftest.py they are discoverable by py.test |
6 | | -# no matter how it is invoked within the source tree. |
7 | | - |
8 | | -from astropy.version import version as astropy_version |
9 | | - |
10 | | -if LooseVersion(astropy_version) < LooseVersion('2.0.3'): |
11 | | - # Astropy is not compatible with the standalone plugins prior this while |
12 | | - # astroquery requires them, so we need this workaround. This will mess |
13 | | - # up the test header, but everything else will work. |
14 | | - from astropy.tests.pytest_plugins import (PYTEST_HEADER_MODULES, |
15 | | - enable_deprecations_as_exceptions, |
16 | | - TESTED_VERSIONS) |
17 | | -elif astropy_version < '3.0': |
18 | | - # With older versions of Astropy, we actually need to import the pytest |
19 | | - # plugins themselves in order to make them discoverable by pytest. |
20 | | - from astropy.tests.pytest_plugins import * |
21 | | -else: |
22 | | - # As of Astropy 3.0, the pytest plugins provided by Astropy are |
23 | | - # automatically made available when Astropy is installed. This means it's |
24 | | - # not necessary to import them here, but we still need to import global |
25 | | - # variables that are used for configuration. |
26 | | - from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS |
27 | | - |
28 | | -from astropy.tests.helper import enable_deprecations_as_exceptions |
| 1 | +"""Configure Test Suite. |
29 | 2 |
|
30 | | -# Add astropy to test header information and remove unused packages. |
31 | | -# Pytest header customisation was introduced in astropy 1.0. |
| 3 | +This file is used to configure the behavior of pytest when using the Astropy |
| 4 | +test infrastructure. It needs to live inside the package in order for it to |
| 5 | +get picked up when running the tests inside an interpreter using |
| 6 | +`pyvo.test()`. |
32 | 7 |
|
33 | | -try: |
34 | | - PYTEST_HEADER_MODULES['Astropy'] = 'astropy' |
35 | | - del PYTEST_HEADER_MODULES['h5py'] |
36 | | - del PYTEST_HEADER_MODULES['Scipy'] |
37 | | - del PYTEST_HEADER_MODULES['Matplotlib'] |
38 | | - del PYTEST_HEADER_MODULES['Pandas'] |
39 | | -except (NameError, KeyError): |
40 | | - pass |
| 8 | +""" |
41 | 9 |
|
42 | | -enable_deprecations_as_exceptions() |
43 | | - |
44 | | - |
45 | | - |
46 | | -# This is to figure out the affiliated package version, rather than |
47 | | -# using Astropy's |
48 | | -from .version import version, astropy_helpers_version |
| 10 | +import os |
49 | 11 |
|
| 12 | +from astropy.version import version as astropy_version |
50 | 13 |
|
51 | | -packagename = os.path.basename(os.path.dirname(__file__)) |
52 | | -TESTED_VERSIONS[packagename] = version |
53 | | -TESTED_VERSIONS['astropy_helpers'] = astropy_helpers_version |
| 14 | +# For Astropy 3.0 and later, we can use the standalone pytest plugin |
| 15 | +if astropy_version < '3.0': |
| 16 | + from astropy.tests.pytest_plugins import * # noqa |
| 17 | + del pytest_report_header |
| 18 | + ASTROPY_HEADER = True |
| 19 | +else: |
| 20 | + try: |
| 21 | + from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS |
| 22 | + ASTROPY_HEADER = True |
| 23 | + except ImportError: |
| 24 | + ASTROPY_HEADER = False |
| 25 | + |
| 26 | + |
| 27 | +def pytest_configure(config): |
| 28 | + """Configure Pytest with Astropy. |
| 29 | +
|
| 30 | + Parameters |
| 31 | + ---------- |
| 32 | + config : pytest configuration |
| 33 | +
|
| 34 | + """ |
| 35 | + if ASTROPY_HEADER: |
| 36 | + |
| 37 | + config.option.astropy_header = True |
| 38 | + |
| 39 | + # Customize the following lines to add/remove entries from the list of |
| 40 | + # packages for which version numbers are displayed when running the tests. |
| 41 | + PYTEST_HEADER_MODULES.pop('Pandas', None) |
| 42 | + PYTEST_HEADER_MODULES['scikit-image'] = 'skimage' |
| 43 | + |
| 44 | + from . import __version__ |
| 45 | + packagename = os.path.basename(os.path.dirname(__file__)) |
| 46 | + TESTED_VERSIONS[packagename] = __version__ |
| 47 | + |
| 48 | +# Uncomment the last two lines in this block to treat all DeprecationWarnings as |
| 49 | +# exceptions. For Astropy v2.0 or later, there are 2 additional keywords, |
| 50 | +# as follow (although default should work for most cases). |
| 51 | +# To ignore some packages that produce deprecation warnings on import |
| 52 | +# (in addition to 'compiler', 'scipy', 'pygments', 'ipykernel', and |
| 53 | +# 'setuptools'), add: |
| 54 | +# modules_to_ignore_on_import=['module_1', 'module_2'] |
| 55 | +# To ignore some specific deprecation warning messages for Python version |
| 56 | +# MAJOR.MINOR or later, add: |
| 57 | +# warnings_to_ignore_by_pyver={(MAJOR, MINOR): ['Message to ignore']} |
| 58 | +# from astropy.tests.helper import enable_deprecations_as_exceptions # noqa |
| 59 | +# enable_deprecations_as_exceptions() |
0 commit comments