def test_issue_11872(self) -> None:
        """Regression test for #11872.

        urllib.error.HTTPError on Python<=3.9 raises KeyError instead of
        AttributeError on invalid attribute access.

        https://github.com/python/cpython/issues/98778
        """
        from email.message import Message
        from urllib.error import HTTPError

        with pytest.raises(HTTPError, match="Not Found") as exc_info:
            raise HTTPError(
                code=404, msg="Not Found", fp=io.BytesIO(), hdrs=Message(), url=""
            )
        exc_info.value.close()  # avoid a resource warning
Regression test for #11872.

        urllib.error.HTTPError on Python<=3.9 raises KeyError instead of
        AttributeError on invalid attribute access.

        https://github.com/python/cpython/issues/98778
        
testing/python/raises.py