    def test_automatic_remote_retrieval(self):
        """
        Automatic retrieval of remote references is deprecated as of v4.18.0.
        """
        ref = "http://bar#/$defs/baz"
        schema = {"$defs": {"baz": {"type": "integer"}}}

        if "requests" in sys.modules:  # pragma: no cover
            self.addCleanup(
                sys.modules.__setitem__, "requests", sys.modules["requests"],
            )
        sys.modules["requests"] = None

        @contextmanager
        def fake_urlopen(request):
            self.assertIsInstance(request, urllib.request.Request)
            self.assertEqual(request.full_url, "http://bar")

            # Ha ha urllib.request.Request "normalizes" header names and
            # Request.get_header does not also normalize them...
            (header, value), = request.header_items()
            self.assertEqual(header.lower(), "user-agent")
            self.assertEqual(
                value, "python-jsonschema (deprecated $ref resolution)",
            )
            yield BytesIO(json.dumps(schema).encode("utf8"))

        validator = validators.Draft202012Validator({"$ref": ref})

        message = "Automatically retrieving remote references "
        patch = mock.patch.object(urllib.request, "urlopen", new=fake_urlopen)

        with patch, self.assertWarnsRegex(DeprecationWarning, message):
            self.assertEqual(
                (validator.is_valid({}), validator.is_valid(37)),
                (False, True),
            )
Automatic retrieval of remote references is deprecated as of v4.18.0.
jsonschema/tests/test_deprecations.py