diff --git a/scripts/core/upstream.py b/scripts/core/upstream.py index d6f462614..369ef67e7 100644 --- a/scripts/core/upstream.py +++ b/scripts/core/upstream.py @@ -385,10 +385,11 @@ def open_retrying( again in this process. What ends the attempts is raised as urllib gave it, except a host that does not resolve (GoneError) and a host muted earlier (RateLimitError). A run that fetches nothing (run_is_offline) - raises OfflineError before anything goes out. + raises OfflineError before anything goes out. A file: address is read + from this machine and is never refused. """ url = request.full_url - if run_is_offline(): + if run_is_offline() and request.type != "file": raise OfflineError(f"{url}: {OFFLINE_ENV} is set, nothing is fetched") host = urllib.parse.urlsplit(url).hostname or "" if host in _exhausted_hosts: diff --git a/tests/test_upstream.py b/tests/test_upstream.py index c81b52bdf..bcda1859a 100644 --- a/tests/test_upstream.py +++ b/tests/test_upstream.py @@ -507,6 +507,14 @@ class TheOfflineSwitchHoldsAtTheGateway(unittest.TestCase): upstream.download("https://host/x", tests.scratch_dir(self) / "x") urlopen.assert_not_called() + def test_a_file_address_is_read_offline(self): + """A file: address is this machine's: refusing it made every test that + serves a fixture through file:// fail once the guard moved into + open_retrying.""" + held = tests.scratch_dir(self) / "held.txt" + held.write_bytes(b"local") + self.assertEqual(upstream.fetch_body(held.as_uri()), b"local") + def test_the_cache_answers_as_an_offline_run(self): cache = str(tests.scratch_dir(self)) with mock.patch.object(upstream, "http_json", side_effect=_no_network), \