liberfa / pyerfa

Python bindings for ERFA routines
https://pyerfa.readthedocs.io
BSD 3-Clause "New" or "Revised" License
34 stars 24 forks source link

Test failed: erfa/tests/helper.py:36: AttributeError #126

Closed Hellseher closed 10 months ago

Hellseher commented 10 months ago

Hi!

During preparation the project for the Guix downstream I've faced with one failing test:

Inputs

=================================== FAILURES ===================================
____________________________ test_errwarn_reporting ____________________________

    def test_errwarn_reporting():
        """
        Test that the ERFA error reporting mechanism works as it should
        """

        # no warning
        erfa.dat(1990, 1, 1, 0.5)

        # check warning is raised for a scalar
>       with catch_warnings() as w:

erfa/tests/test_erfa.py:175:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
erfa/tests/helper.py:112: in __enter__
    treat_deprecations_as_exceptions()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def treat_deprecations_as_exceptions():
        """
        Turn all DeprecationWarnings (which indicate deprecated uses of
        Python itself or Numpy) into exceptions so that we find
        out about them early.

        This completely resets the warning filters and any "already seen"
        warning state.
        """
        # First, totally reset the warning state. The modules may change during
        # this iteration thus we copy the original state to a list to iterate
        # on. See https://github.com/astropy/astropy/pull/5513.
        for module in list(sys.modules.values()):
            # We don't want to deal with six.MovedModules, only "real"
            # modules. FIXME: we no more use six, this should be useless ?
            if (isinstance(module, types.ModuleType) and
                    hasattr(module, '__warningregistry__')):
>               del module.__warningregistry__
E               AttributeError: __warningregistry__

erfa/tests/helper.py:36: AttributeError
=========================== short test summary info ============================
FAILED erfa/tests/test_erfa.py::test_errwarn_reporting - AttributeError: __wa...
============= 1 failed, 273 passed, 2 skipped, 5 xfailed in 1.47s ==============
pllim commented 10 months ago

Looks like treat_deprecations_as_exceptions() is copied over from old astropy code. This should not be used anymore. Instead please use https://docs.pytest.org/en/stable/how-to/capture-warnings.html directly.

pllim commented 10 months ago

In fact, I think the whole helper.py can be removed. But other changes to pytest setup is necessary to replace the functionality there and I do not have time to look into it. Shouldn't be hard, just tedious.