From a93fc40266fdec42c6eaae5950530e9b6cd3735d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 13 Aug 2026 20:31:59 +0300 Subject: [PATCH] gh-155731: Clean up files left by test_import (GH-155735) test_import() and test_unencodable_filename() left the __pycache__ directory created for a temporary module, and test_import_in_del_does_not_crash() left the script it created. (cherry picked from commit b0ba60e28906c75dd43afe49791740c62205660f) Co-authored-by: Serhiy Storchaka --- Lib/test/test_import/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index f698e23f69905d6..6a2557d522b698f 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -506,6 +506,7 @@ def test_with_extension(ext): forget(TESTFN) unlink(source) unlink(pyc) + rmtree('__pycache__') sys.path.insert(0, os.curdir) try: @@ -685,6 +686,7 @@ def __del__(self): import importlib sys.argv.insert(0, C()) """)) + self.addCleanup(unlink, testfn) script_helper.assert_python_ok(testfn) @skip_if_dont_write_bytecode @@ -2082,6 +2084,7 @@ def test_unencodable_filename(self): # encode filenames, especially on Windows pyname = script_helper.make_script('', TESTFN_UNENCODABLE, 'pass') self.addCleanup(unlink, pyname) + self.addCleanup(rmtree, '__pycache__') name = pyname[:-3] script_helper.assert_python_ok("-c", "mod = __import__(%a)" % name, __isolated=False)