Bug 2273564 - python-astropy fails to build with pytest 8: Failed: DID NOT WARN. No warnings of type (<class 'astropy.utils.exceptions.AstropyUserWarning'>,) were emitted.
Summary: python-astropy fails to build with pytest 8: Failed: DID NOT WARN. No warning...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: python-astropy
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Sergio Pascual
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 2256331
TreeView+ depends on / blocked
 
Reported: 2024-04-05 07:52 UTC by Tomáš Hrnčiar
Modified: 2024-09-25 09:28 UTC (History)
4 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2024-09-25 09:28:29 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Tomáš Hrnčiar 2024-04-05 07:52:47 UTC
python-astropy fails to build with pytest 8.

=================================== FAILURES ===================================
____ TestHDUListFunctions.test_no_resource_warning_raised_on_non_fits_file _____

self = <astropy.io.fits.tests.test_hdulist.TestHDUListFunctions object at 0x7f38f72ee330>

    def test_no_resource_warning_raised_on_non_fits_file(self):
        """
        Regression test for https://github.com/astropy/astropy/issues/6168
    
        The ResourceWarning shows up when (in python 3+) you try to
        open a non-FITS file when using a filename.
        """
    
        # To avoid creating the file multiple times the tests are
        # all included in one test file. See the discussion to the
        # PR at https://github.com/astropy/astropy/issues/6168
        #
        filename = self.temp("not-fits.fits")
        with open(filename, mode="w") as f:
            f.write("# header line\n")
            f.write("0.1 0.2\n")
    
        # Opening the file should raise an OSError however the file
        # is opened (there are two distinct code paths, depending on
        # whether ignore_missing_end is True or False).
        #
        # Explicit tests are added to make sure the file handle is not
        # closed when passed in to fits.open. In this case the ResourceWarning
        # was not raised.
    
        # Make sure that files opened by the user are not closed
        with open(filename, mode="rb") as f:
            with pytest.raises(OSError):
                fits.open(f, ignore_missing_end=False)
    
            assert not f.closed
    
        with open(filename, mode="rb") as f:
            with pytest.raises(OSError), pytest.warns(VerifyWarning):
>               fits.open(f, ignore_missing_end=True)

astropy/io/fits/tests/test_hdulist.py:1137: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astropy/io/fits/hdu/hdulist.py:213: in fitsopen
    return HDUList.fromfile(
astropy/io/fits/hdu/hdulist.py:476: in fromfile
    return cls._readfrom(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'astropy.io.fits.hdu.hdulist.HDUList'>
fileobj = <astropy.io.fits.file._File <_io.BufferedReader name='/tmp/fits-test-_vauz50v/not-fits.fits'>>
data = None, mode = 'readonly', memmap = None, cache = True
lazy_load_hdus = True, ignore_missing_simple = False, use_fsspec = None
fsspec_kwargs = None
kwargs = {'ignore_missing_end': True, 'save_backup': False, 'uint': True}
hdulist = [], pos = 0, simple = b'# header line\n0.1 0.2\n', match_sig = False
match_sig_relaxed = None

    @classmethod
    def _readfrom(
        cls,
        fileobj=None,
        data=None,
        mode=None,
        memmap=None,
        cache=True,
        lazy_load_hdus=True,
        ignore_missing_simple=False,
        *,
        use_fsspec=None,
        fsspec_kwargs=None,
        **kwargs,
    ):
        """
        Provides the implementations from HDUList.fromfile and
        HDUList.fromstring, both of which wrap this method, as their
        implementations are largely the same.
        """
        if fileobj is not None:
            if not isinstance(fileobj, _File):
                # instantiate a FITS file object (ffo)
                fileobj = _File(
                    fileobj,
                    mode=mode,
                    memmap=memmap,
                    cache=cache,
                    use_fsspec=use_fsspec,
                    fsspec_kwargs=fsspec_kwargs,
                )
            # The Astropy mode is determined by the _File initializer if the
            # supplied mode was None
            mode = fileobj.mode
            hdulist = cls(file=fileobj)
        else:
            if mode is None:
                # The default mode
                mode = "readonly"
    
            hdulist = cls(file=data)
            # This method is currently only called from HDUList.fromstring and
            # HDUList.fromfile.  If fileobj is None then this must be the
            # fromstring case; the data type of ``data`` will be checked in the
            # _BaseHDU.fromstring call.
    
        if (
            not ignore_missing_simple
            and hdulist._file
            and hdulist._file.mode != "ostream"
            and hdulist._file.size > 0
        ):
            pos = hdulist._file.tell()
            # FITS signature is supposed to be in the first 30 bytes, but to
            # allow reading various invalid files we will check in the first
            # card (80 bytes).
            simple = hdulist._file.read(80)
            match_sig = simple[:29] == FITS_SIGNATURE[:-1] and simple[29:30] in (
                b"T",
                b"F",
            )
    
            if not match_sig:
                # Check the SIMPLE card is there but not written correctly
                match_sig_relaxed = re.match(rb"SIMPLE\s*=\s*[T|F]", simple)
    
                if match_sig_relaxed:
                    warnings.warn(
                        "Found a SIMPLE card but its format doesn't"
                        " respect the FITS Standard",
                        VerifyWarning,
                    )
                else:
                    if hdulist._file.close_on_error:
                        hdulist._file.close()
>                   raise OSError(
                        "No SIMPLE card found, this file does not appear to "
                        "be a valid FITS file. If this is really a FITS file, "
                        "try with ignore_missing_simple=True"
                    )
E                   OSError: No SIMPLE card found, this file does not appear to be a valid FITS file. If this is really a FITS file, try with ignore_missing_simple=True

astropy/io/fits/hdu/hdulist.py:1198: OSError

During handling of the above exception, another exception occurred:

self = <astropy.io.fits.tests.test_hdulist.TestHDUListFunctions object at 0x7f38f72ee330>

    def test_no_resource_warning_raised_on_non_fits_file(self):
        """
        Regression test for https://github.com/astropy/astropy/issues/6168
    
        The ResourceWarning shows up when (in python 3+) you try to
        open a non-FITS file when using a filename.
        """
    
        # To avoid creating the file multiple times the tests are
        # all included in one test file. See the discussion to the
        # PR at https://github.com/astropy/astropy/issues/6168
        #
        filename = self.temp("not-fits.fits")
        with open(filename, mode="w") as f:
            f.write("# header line\n")
            f.write("0.1 0.2\n")
    
        # Opening the file should raise an OSError however the file
        # is opened (there are two distinct code paths, depending on
        # whether ignore_missing_end is True or False).
        #
        # Explicit tests are added to make sure the file handle is not
        # closed when passed in to fits.open. In this case the ResourceWarning
        # was not raised.
    
        # Make sure that files opened by the user are not closed
        with open(filename, mode="rb") as f:
            with pytest.raises(OSError):
                fits.open(f, ignore_missing_end=False)
    
            assert not f.closed
    
        with open(filename, mode="rb") as f:
>           with pytest.raises(OSError), pytest.warns(VerifyWarning):
E           Failed: DID NOT WARN. No warnings of type (<class 'astropy.io.fits.verify.VerifyWarning'>,) were emitted.
E            Emitted warnings: [].

astropy/io/fits/tests/test_hdulist.py:1136: Failed
_________________ test_deprecated_argument_multi_deprecation_2 _________________

    def test_deprecated_argument_multi_deprecation_2():
        @deprecated_renamed_argument(
            ["x", "y", "z"], ["a", "b", "c"], [1.3, 1.2, 1.3], relax=[True, True, False]
        )
        def test(a, b, c):
            return a, b, c
    
        with pytest.warns(AstropyUserWarning) as w:
            assert test(x=1, y=2, z=3, b=3) == (1, 3, 3)
        assert len(w) == 4
    
        with pytest.warns(AstropyUserWarning) as w:
            assert test(x=1, y=2, z=3, a=3) == (3, 2, 3)
        assert len(w) == 4
    
        with pytest.raises(TypeError), pytest.warns(AstropyUserWarning):
>           assert test(x=1, y=2, z=3, c=5) == (1, 2, 5)

astropy/utils/tests/test_decorators.py:450: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

args = (), kwargs = {'a': 1, 'b': 2, 'c': 5}, i = 2
msg = '"z" was deprecated in version 1.3 and will be removed in a future version. Use argument "c" instead.'
value = 3, newarg_in_args = False, newarg_in_kwargs = True

    @functools.wraps(function)
    def wrapper(*args, **kwargs):
        for i in range(n):
            msg = message[i] or (
                f'"{old_name[i]}" was deprecated in '
                f"version {since[i]} and will be removed "
                "in a future version. "
            )
            # The only way to have oldkeyword inside the function is
            # that it is passed as kwarg because the oldkeyword
            # parameter was renamed to newkeyword.
            if old_name[i] in kwargs:
                value = kwargs.pop(old_name[i])
                # Display the deprecation warning only when it's not
                # pending.
                if not pending[i]:
                    if not message[i]:
                        if new_name[i] is not None:
                            msg += f'Use argument "{new_name[i]}" instead.'
                        elif alternative:
                            msg += f"\n        Use {alternative} instead."
                    warnings.warn(msg, warning_type, stacklevel=2)
    
                # Check if the newkeyword was given as well.
                newarg_in_args = position[i] is not None and len(args) > position[i]
                newarg_in_kwargs = new_name[i] in kwargs
    
                if newarg_in_args or newarg_in_kwargs:
                    if not pending[i]:
                        # If both are given print a Warning if relax is
                        # True or raise an Exception is relax is False.
                        if relax[i]:
                            warnings.warn(
                                f'"{old_name[i]}" and "{new_name[i]}" '
                                "keywords were set. "
                                f'Using the value of "{new_name[i]}".',
                                AstropyUserWarning,
                            )
                        else:
>                           raise TypeError(
                                f'cannot specify both "{old_name[i]}" and '
                                f'"{new_name[i]}".'
                            )
E                           TypeError: cannot specify both "z" and "c".

astropy/utils/decorators.py:578: TypeError

During handling of the above exception, another exception occurred:

    def test_deprecated_argument_multi_deprecation_2():
        @deprecated_renamed_argument(
            ["x", "y", "z"], ["a", "b", "c"], [1.3, 1.2, 1.3], relax=[True, True, False]
        )
        def test(a, b, c):
            return a, b, c
    
        with pytest.warns(AstropyUserWarning) as w:
            assert test(x=1, y=2, z=3, b=3) == (1, 3, 3)
        assert len(w) == 4
    
        with pytest.warns(AstropyUserWarning) as w:
            assert test(x=1, y=2, z=3, a=3) == (3, 2, 3)
        assert len(w) == 4
    
>       with pytest.raises(TypeError), pytest.warns(AstropyUserWarning):
E       Failed: DID NOT WARN. No warnings of type (<class 'astropy.utils.exceptions.AstropyUserWarning'>,) were emitted.
E        Emitted warnings: [ AstropyDeprecationWarning('"x" was deprecated in version 1.3 and will be removed in a future version. Use argument "a" instead.'),
E         AstropyDeprecationWarning('"y" was deprecated in version 1.2 and will be removed in a future version. Use argument "b" instead.'),
E         AstropyDeprecationWarning('"z" was deprecated in version 1.3 and will be removed in a future version. Use argument "c" instead.')].

astropy/utils/tests/test_decorators.py:449: Failed
=========================== short test summary info ============================
FAILED astropy/io/fits/tests/test_hdulist.py::TestHDUListFunctions::test_no_resource_warning_raised_on_non_fits_file
FAILED astropy/utils/tests/test_decorators.py::test_deprecated_argument_multi_deprecation_2
= 2 failed, 26297 passed, 591 skipped, 3 deselected, 180 xfailed, 260 warnings in 350.38s (0:05:50) =

https://docs.pytest.org/en/stable/changelog.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/thrnciar/pytest/fedora-rawhide-x86_64/07247743-python-astropy/

For all our attempts to build python-astropy with pytest 8, see:
https://copr.fedorainfracloud.org/coprs/thrnciar/pytest/package/python-astropy/

Let us know here if you have any questions.

Pytest 8 is planned to be included in Fedora 41. And this bugzilla is a
heads up before we merge new pytest into rawhide. For more info see a Fedora Change
proposal https://fedoraproject.org/wiki/Changes/Pytest_8

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.


Note You need to log in before you can comment on or make changes to this bug.