def safe(func):
    @patch("appvalidator.testcases.webappbase.test_icon")
    @wraps(func)
    def wrap(test_icon, *args, **kwargs):
        # Assert that we're not double-mocking `requests.get`.
        from requests import get as _r_g
        assert not isinstance(_r_g, (MagicMock, Mock)), (
            "`requests.get` already mocked")

        with patch("requests.get") as r_g:
            def request_generator(*args, **kwargs):
                url = kwargs.get("url", args[0])
                if "://" not in url:
                    raise requests.exceptions.MissingSchema

                request = Mock()
                request.text = "foo bar"
                request.status_code = 200
                request.encoding = 'UTF-8'
                # The first bit is the return value. The second bit tells whatever
                # is requesting the data that there's no more data.
                request.raw.read.side_effect = [request.text, ""]
                return request

            r_g.side_effect = request_generator
            return func(*args, **kwargs)
    return wrap
Make sure that a test does not access external resources.
dataset/ETHPy150Open mozilla/app-validator/tests/helper.py/safe