]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129192: Use `EnvironmentVarGuard` to restore environment variables (#129193)
authorKirill Podoprigora <kirill.bast9@mail.ru>
Wed, 22 Jan 2025 20:39:26 +0000 (22:39 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Jan 2025 20:39:26 +0000 (20:39 +0000)
Co-authored-by: Cody Maloney <cmaloney@theoreticalchaos.com>
Lib/test/test_zipfile/test_core.py

index ab5fb650084327d7fd4426b76871f651f5a8b62d..76b1de0e3519f98bf1fd74a729da08a6a64282de 100644 (file)
@@ -1801,17 +1801,17 @@ class OtherTests(unittest.TestCase):
                     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."""