Fix unclosed resource warnings in fetch backend tests

This commit is contained in:
Kovid Goyal 2024-08-26 16:01:53 +05:30
parent d8d63646f4
commit 60555c1389
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 4 deletions

View File

@ -102,6 +102,12 @@ class FakeResponse:
def close(self):
self._data.close()
def __enter__(self):
return self
def __exit__(self, *a):
self._data.close()
def shutdown_browser(bref):
br = bref()

View File

@ -109,10 +109,10 @@ class TestFetchBackend(unittest.TestCase):
req = Request(url, headers=headers)
else:
req = url
res = br.open(req, data=data, timeout=timeout)
raw = res.read()
ans = json.loads(raw)
ans['final_url'] = res.geturl()
with br.open(req, data=data, timeout=timeout) as res:
raw = res.read()
ans = json.loads(raw)
ans['final_url'] = res.geturl()
return ans
def test_with_timeout(no_response=True):