https://github.com/python/cpython/commit/fc6d4b71eb6bb4dcef3def286302e6bec37aec9f
commit: fc6d4b71eb6bb4dcef3def286302e6bec37aec9f
branch: main
author: Kirill Podoprigora <[email protected]>
committer: Eclips4 <[email protected]>
date: 2025-01-22T20:39:26Z
summary:

gh-129192: Use `EnvironmentVarGuard` to restore environment variables (#129193)

Co-authored-by: Cody Maloney <[email protected]>

files:
M Lib/test/test_zipfile/test_core.py

diff --git a/Lib/test/test_zipfile/test_core.py 
b/Lib/test/test_zipfile/test_core.py
index ab5fb650084327..76b1de0e3519f9 100644
--- a/Lib/test/test_zipfile/test_core.py
+++ b/Lib/test/test_zipfile/test_core.py
@@ -1801,17 +1801,17 @@ def test_write_with_source_date_epoch(self):
                     self.assertAlmostEqual(z_time, g_time, delta=1)
 
     def test_write_without_source_date_epoch(self):
-        if 'SOURCE_DATE_EPOCH' in os.environ:
-            del os.environ['SOURCE_DATE_EPOCH']
+        with os_helper.EnvironmentVarGuard() as env:
+            del env['SOURCE_DATE_EPOCH']
 
-        with zipfile.ZipFile(TESTFN, "w") as zf:
-            zf.writestr("test_no_source_date_epoch.txt", "Testing without 
SOURCE_DATE_EPOCH")
+            with zipfile.ZipFile(TESTFN, "w") as zf:
+                zf.writestr("test_no_source_date_epoch.txt", "Testing without 
SOURCE_DATE_EPOCH")
 
-        with zipfile.ZipFile(TESTFN, "r") as zf:
-            zip_info = zf.getinfo("test_no_source_date_epoch.txt")
-            current_time = time.localtime()[:6]
-            for z_time, c_time in zip(zip_info.date_time, current_time):
-                self.assertAlmostEqual(z_time, c_time, delta=1)
+            with zipfile.ZipFile(TESTFN, "r") as zf:
+                zip_info = zf.getinfo("test_no_source_date_epoch.txt")
+                current_time = time.localtime()[:6]
+                for z_time, c_time in zip(zip_info.date_time, current_time):
+                    self.assertAlmostEqual(z_time, c_time, delta=1)
 
     def test_close(self):
         """Check that the zipfile is closed after the 'with' block."""

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to