Skip to content

Tests should collect without optional dependencies #10246

Open

Description

@bsipocz

Currently we silence import issues at test collection (see scientific-python/pytest-doctestplus#108 and xrefs therein) which is the same behaviour as doctest would do when doctest_ignore_import_error is opted in.

Some of the offending modules are also picked up at import tests in #7952

Here is a hopefully full list:

$ pytest astropy
================================================= test session starts ==================================================
platform darwin -- Python 3.8.2, pytest-5.4.1, py-1.8.1, pluggy-0.13.1

Running tests with Astropy version 4.1.dev1224+gf3060a1f1.
Running tests in astropy.

Date: 2020-04-30T16:29:49

Platform: macOS-10.13.6-x86_64-i386-64bit

Executable: /Users/bsipocz/miniconda/envs/test_imports/bin/python

Full Python Version: 
3.8.2 (default, Mar 26 2020, 10:43:30) 
[Clang 4.0.1 (tags/RELEASE_401/final)]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Package versions: 
Numpy: 1.18.3
Scipy: not available
Matplotlib: not available
h5py: not available
Pandas: not available
Cython: not available
Scikit-image: not available
asdf: not available

Using Astropy options: remote_data: none.

rootdir: /Users/bsipocz/munka/devel/astropy, inifile: setup.cfg
plugins: arraydiff-0.3, remotedata-0.3.2, hypothesis-5.10.4, filter-subpackage-0.1.1, openfiles-0.5.0, astropy-header-0.1.2, cov-2.8.1, doctestplus-0.7.0.dev0
collected 14083 items / 36 errors / 72 skipped / 13975 selected                                                        

======================================================== ERRORS ========================================================
___________________________________ ERROR collecting astropy/_erfa/setup_package.py ____________________________________
astropy/_erfa/setup_package.py:9: in <module>
    from extension_helpers import import_file
E   ModuleNotFoundError: No module named 'extension_helpers'
__________________________________ ERROR collecting astropy/io/fits/setup_package.py ___________________________________
astropy/io/fits/setup_package.py:12: in <module>
    from extension_helpers import pkg_config, get_compiler
E   ModuleNotFoundError: No module named 'extension_helpers'
_______________________________________ ERROR collecting astropy/io/misc/yaml.py _______________________________________
astropy/io/misc/yaml.py:81: in <module>
    import yaml
E   ModuleNotFoundError: No module named 'yaml'

During handling of the above exception, another exception occurred:
astropy/io/misc/yaml.py:83: in <module>
    raise ImportError('`import yaml` failed, PyYAML package is required for YAML')
E   ImportError: `import yaml` failed, PyYAML package is required for YAML
__________________________________ ERROR collecting astropy/io/misc/asdf/extension.py __________________________________
astropy/io/misc/asdf/extension.py:6: in <module>
    from asdf.extension import AsdfExtension, BuiltinExtension
E   ModuleNotFoundError: No module named 'asdf'
____________________________________ ERROR collecting astropy/io/misc/asdf/types.py ____________________________________
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
___________________________ ERROR collecting astropy/io/misc/asdf/tags/coordinates/angle.py ____________________________
astropy/io/misc/asdf/tags/coordinates/angle.py:6: in <module>
    from astropy.io.misc.asdf.tags.unit.quantity import QuantityType
astropy/io/misc/asdf/tags/unit/quantity.py:7: in <module>
    from asdf.tags.core import NDArrayType
E   ModuleNotFoundError: No module named 'asdf'
_______________________ ERROR collecting astropy/io/misc/asdf/tags/coordinates/earthlocation.py ________________________
astropy/io/misc/asdf/tags/coordinates/earthlocation.py:5: in <module>
    from ...types import AstropyType
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
___________________________ ERROR collecting astropy/io/misc/asdf/tags/coordinates/frames.py ___________________________
astropy/io/misc/asdf/tags/coordinates/frames.py:6: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
_______________________ ERROR collecting astropy/io/misc/asdf/tags/coordinates/representation.py _______________________
astropy/io/misc/asdf/tags/coordinates/representation.py:5: in <module>
    from astropy.io.misc.asdf.types import AstropyType
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
__________________________ ERROR collecting astropy/io/misc/asdf/tags/coordinates/skycoord.py __________________________
astropy/io/misc/asdf/tags/coordinates/skycoord.py:6: in <module>
    from ...types import AstropyType
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
_______________________________ ERROR collecting astropy/io/misc/asdf/tags/fits/fits.py ________________________________
astropy/io/misc/asdf/tags/fits/fits.py:9: in <module>
    from astropy.io.misc.asdf.types import AstropyType, AstropyAsdfType
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
______________________________ ERROR collecting astropy/io/misc/asdf/tags/table/table.py _______________________________
astropy/io/misc/asdf/tags/table/table.py:5: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
_______________________________ ERROR collecting astropy/io/misc/asdf/tags/time/time.py ________________________________
astropy/io/misc/asdf/tags/time/time.py:7: in <module>
    from asdf.versioning import AsdfSpec
E   ModuleNotFoundError: No module named 'asdf'
_____________________________ ERROR collecting astropy/io/misc/asdf/tags/time/timedelta.py _____________________________
astropy/io/misc/asdf/tags/time/timedelta.py:9: in <module>
    from ...types import AstropyType
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
____________________________ ERROR collecting astropy/io/misc/asdf/tags/transform/basic.py _____________________________
astropy/io/misc/asdf/tags/transform/basic.py:4: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
___________________________ ERROR collecting astropy/io/misc/asdf/tags/transform/compound.py ___________________________
astropy/io/misc/asdf/tags/transform/compound.py:3: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
______________________ ERROR collecting astropy/io/misc/asdf/tags/transform/functional_models.py _______________________
astropy/io/misc/asdf/tags/transform/functional_models.py:7: in <module>
    from .basic import TransformType
astropy/io/misc/asdf/tags/transform/basic.py:4: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
_____________________________ ERROR collecting astropy/io/misc/asdf/tags/transform/math.py _____________________________
astropy/io/misc/asdf/tags/transform/math.py:10: in <module>
    from .basic import TransformType
astropy/io/misc/asdf/tags/transform/basic.py:4: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
_______________________ ERROR collecting astropy/io/misc/asdf/tags/transform/physical_models.py ________________________
astropy/io/misc/asdf/tags/transform/physical_models.py:8: in <module>
    from .basic import TransformType
astropy/io/misc/asdf/tags/transform/basic.py:4: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
__________________________ ERROR collecting astropy/io/misc/asdf/tags/transform/polynomial.py __________________________
astropy/io/misc/asdf/tags/transform/polynomial.py:7: in <module>
    from asdf.versioning import AsdfVersion
E   ModuleNotFoundError: No module named 'asdf'
__________________________ ERROR collecting astropy/io/misc/asdf/tags/transform/powerlaws.py ___________________________
astropy/io/misc/asdf/tags/transform/powerlaws.py:7: in <module>
    from .basic import TransformType
astropy/io/misc/asdf/tags/transform/basic.py:4: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
_________________________ ERROR collecting astropy/io/misc/asdf/tags/transform/projections.py __________________________
astropy/io/misc/asdf/tags/transform/projections.py:7: in <module>
    from .basic import TransformType
astropy/io/misc/asdf/tags/transform/basic.py:4: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
___________________________ ERROR collecting astropy/io/misc/asdf/tags/transform/tabular.py ____________________________
astropy/io/misc/asdf/tags/transform/tabular.py:9: in <module>
    from .basic import TransformType
astropy/io/misc/asdf/tags/transform/basic.py:4: in <module>
    from asdf import tagged
E   ModuleNotFoundError: No module named 'asdf'
____________________________ ERROR collecting astropy/io/misc/asdf/tags/unit/equivalency.py ____________________________
astropy/io/misc/asdf/tags/unit/equivalency.py:8: in <module>
    from astropy.io.misc.asdf.types import AstropyType
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
_____________________________ ERROR collecting astropy/io/misc/asdf/tags/unit/quantity.py ______________________________
astropy/io/misc/asdf/tags/unit/quantity.py:7: in <module>
    from asdf.tags.core import NDArrayType
E   ModuleNotFoundError: No module named 'asdf'
_______________________________ ERROR collecting astropy/io/misc/asdf/tags/unit/unit.py ________________________________
astropy/io/misc/asdf/tags/unit/unit.py:7: in <module>
    from astropy.io.misc.asdf.types import AstropyAsdfType
astropy/io/misc/asdf/types.py:4: in <module>
    from asdf.types import CustomType, ExtensionTypeMeta
E   ModuleNotFoundError: No module named 'asdf'
__________________________________ ERROR collecting astropy/modeling/setup_package.py __________________________________
astropy/modeling/setup_package.py:9: in <module>
    from extension_helpers import import_file
E   ModuleNotFoundError: No module named 'extension_helpers'
____________________________________ ERROR collecting astropy/tests/image_tests.py _____________________________________
astropy/tests/image_tests.py:1: in <module>
    import matplotlib
E   ModuleNotFoundError: No module named 'matplotlib'
_________________ ERROR collecting astropy/timeseries/periodograms/lombscargle/fix-parents-astropy.py __________________
astropy/timeseries/periodograms/lombscargle/fix-parents-astropy.py:7: in <module>
    commit = os.environ['GIT_COMMIT']
../../../miniconda/envs/test_imports/lib/python3.8/os.py:675: in __getitem__
    raise KeyError(key) from None
E   KeyError: 'GIT_COMMIT'
________ ERROR collecting astropy/timeseries/periodograms/lombscargle/implementations/lomb_scargle_multiband.py ________
astropy/timeseries/periodograms/lombscargle/implementations/lomb_scargle_multiband.py:11: in <module>
    from .modeler import PeriodicModelerMultiband
astropy/timeseries/periodograms/lombscargle/implementations/modeler.py:5: in <module>
    from .optimizer import LinearScanOptimizer
E   ModuleNotFoundError: No module named 'astropy.timeseries.periodograms.lombscargle.implementations.optimizer'
_______________ ERROR collecting astropy/timeseries/periodograms/lombscargle/implementations/modeler.py ________________
astropy/timeseries/periodograms/lombscargle/implementations/modeler.py:5: in <module>
    from .optimizer import LinearScanOptimizer
E   ModuleNotFoundError: No module named 'astropy.timeseries.periodograms.lombscargle.implementations.optimizer'
___________ ERROR collecting astropy/timeseries/periodograms/lombscargle/implementations/naive_multiband.py ____________
astropy/timeseries/periodograms/lombscargle/implementations/naive_multiband.py:12: in <module>
    from scipy.stats import mode
E   ModuleNotFoundError: No module named 'scipy'
__ ERROR collecting astropy/timeseries/periodograms/lombscargle/implementations/tests/test_lomb_scargle_multiband.py ___
astropy/timeseries/periodograms/lombscargle/implementations/tests/test_lomb_scargle_multiband.py:5: in <module>
    from nose import SkipTest
E   ModuleNotFoundError: No module named 'nose'
__ ERROR collecting astropy/timeseries/periodograms/lombscargle/implementations/tests/test_lomb_scargle_multiband.py ___
ImportError while importing test module '/Users/bsipocz/munka/devel/astropy/astropy/timeseries/periodograms/lombscargle/implementations/tests/test_lomb_scargle_multiband.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
astropy/timeseries/periodograms/lombscargle/implementations/tests/test_lomb_scargle_multiband.py:5: in <module>
    from nose import SkipTest
E   ModuleNotFoundError: No module named 'nose'
_________________________________ ERROR collecting astropy/utils/xml/setup_package.py __________________________________
astropy/utils/xml/setup_package.py:10: in <module>
    from extension_helpers import pkg_config
E   ModuleNotFoundError: No module named 'extension_helpers'
____________________________________ ERROR collecting astropy/wcs/setup_package.py _____________________________________
astropy/wcs/setup_package.py:16: in <module>
    from extension_helpers import import_file, write_if_different, get_compiler, pkg_config
E   ModuleNotFoundError: No module named 'extension_helpers'
=============================================== short test summary info ================================================

Activity

  1. bsipocz commented on May 1, 2020

    @bsipocz
    MemberAuthor

    (ignore the timeseries ones, that's due to some local only files I haven't noticed in time)

  2. astrofrog commented on May 1, 2020

    @astrofrog
    Member

    Fundamentally the issue is that pytest-doctestplus shouldn't be trying to import all files in the first place, I think it should be possible to extract docstrings/doctests without importing. I think it's ok to have imports in setup_package.py that are build-time requirements only, and don't have to be available at testing time, so I don't consider it a bug in astropy core as such.

  3. bsipocz commented on May 1, 2020

    @bsipocz
    MemberAuthor

    Ok, that indeed makes sense for the setup_package/extension helpers case. But asdf and pyyaml are different beasts, and ideally should behave similarly to e.g h5py or pandas which are patched around to check for availability first

  4. astrofrog commented on May 1, 2020

    @astrofrog
    Member

    I agree in general, although in the case of asdf I think it's reasonable to expect that importing astropy.io.misc.asdf would require asdf?

  5. bsipocz commented on May 1, 2020

    @bsipocz
    MemberAuthor

    I agree that it seems reasonable, but some other modules don't have the issue (though one can argue they are much more simple, e.g.astropy.io.mist.hdf5)

  6. pllim commented on May 1, 2020

    @pllim
    Member
  7. self-assigned this
    on May 1, 2020
  8. vvasuki commented on Sep 21, 2020

    @vvasuki
  9. removed their assignment
    on Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions