diff --git a/smart_open/tests/test_smart_open.py b/smart_open/tests/test_smart_open.py index e3727271..e31f48b7 100644 --- a/smart_open/tests/test_smart_open.py +++ b/smart_open/tests/test_smart_open.py @@ -1441,7 +1441,8 @@ def gzip_compress(data, filename=None): buf = io.BytesIO() buf.name = filename with mock.patch('time.time', _MOCK_TIME): - gzip.GzipFile(fileobj=buf, mode='w').write(data) + with gzip.GzipFile(fileobj=buf, mode='w') as gz: + gz.write(data) return buf.getvalue()