[Python-checkins] bpo-28655: Fix test_import.test_missing_source_legacy() (GH-9589)

Victor Stinner webhook-mailer at python.org
Wed Sep 26 12:09:42 EDT 2018


https://github.com/python/cpython/commit/43500a5907eb9ae2e470dcbffe73012cd456f5a1
commit: 43500a5907eb9ae2e470dcbffe73012cd456f5a1
branch: 3.6
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018-09-26T09:09:32-07:00
summary:

bpo-28655: Fix test_import.test_missing_source_legacy() (GH-9589)

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 at gmail.com>

files:
M Lib/test/test_import/__init__.py

diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index b73a96f75700..6fb7cb0669cc 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -779,8 +779,11 @@ def test_missing_source_legacy(self):
         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.



More information about the Python-checkins mailing list