1
"""
2
Different implementations of the ``./setup.py test`` command depending on
3
what's locally available.
4

5
If Astropy v1.1 or later is available it should be possible to import
6
AstropyTest from ``astropy.tests.command``. Otherwise there is a skeleton
7
implementation that allows users to at least discover the ``./setup.py test``
8
command and learn that they need Astropy to run it.
9
"""
10

11 20
import os
12 20
from ..utils import import_file
13

14
# Previously these except statements caught only ImportErrors, but there are
15
# some other obscure exceptional conditions that can occur when importing
16
# astropy.tests (at least on older versions) that can cause these imports to
17
# fail
18

19 20
try:
20

21
    # If we are testing astropy itself, we need to use import_file to avoid
22
    # actually importing astropy (just the file we need).
23 20
    command_file = os.path.join('astropy', 'tests', 'command.py')
24 20
    if os.path.exists(command_file):
25 0
        AstropyTest = import_file(command_file, 'astropy_tests_command').AstropyTest
26
    else:
27 20
        import astropy  # noqa
28 0
        from astropy.tests.command import AstropyTest
29

30 20
except Exception:
31

32
    # No astropy at all--provide the dummy implementation
33 20
    from ._dummy import _DummyCommand
34

35 20
    class AstropyTest(_DummyCommand):
36 20
        command_name = 'test'
37 20
        description = 'Run the tests for this package'
38 20
        error_msg = (
39
                "The 'test' command requires the astropy package to be "
40
                "installed and importable.")

Read our documentation on viewing source code .

Loading