From 844abda318874cdf4714eefe0c15f1bb43782c98 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 26 Sep 2018 17:02:21 +0200 Subject: [PATCH] bpo-28655: Fix test_import.test_missing_source_legacy() 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 --- Lib/test/test_import/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index b73a96f757005e..6fb7cb0669cc13 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.