]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-28655: Fix test_import.test_missing_source_legacy() (GH-9589)
authorVictor Stinner <vstinner@redhat.com>
Wed, 26 Sep 2018 16:09:32 +0000 (09:09 -0700)
committerGitHub <noreply@github.com>
Wed, 26 Sep 2018 16:09:32 +0000 (09:09 -0700)
bpo-28655, bpo-33053: test_import.test_missing_source_legacy() now
removes the .pyc file that it creates to avoid leaking a file.

Fix extract from commit d5d9e02dd3c6df06a8dd9ce75ee9b52976420a8b.

Co-Authored-By: Nick Coghlan <ncoghlan@gmail.com>
Lib/test/test_import/__init__.py

index b73a96f757005ecf54a9bc8bb5cae214d91ad5a8..6fb7cb0669cc13646dfc93693b25225ceac35e5f 100644 (file)
@@ -779,8 +779,11 @@ class PycacheTests(unittest.TestCase):
         unload(TESTFN)
         importlib.invalidate_caches()
         m = __import__(TESTFN)
-        self.assertEqual(m.__file__,
-                         os.path.join(os.curdir, os.path.relpath(pyc_file)))
+        try:
+            self.assertEqual(m.__file__,
+                             os.path.join(os.curdir, os.path.relpath(pyc_file)))
+        finally:
+            os.remove(pyc_file)
 
     def test___cached__(self):
         # Modules now also have an __cached__ that points to the pyc file.