changeset: 92458:f9c8c4a22415 tag: tip user: Victor Stinner date: Wed Sep 17 23:58:39 2014 +0200 files: Lib/test/test_imp.py Lib/test/test_import.py Lib/test/test_pdb.py Lib/test/test_posix.py Lib/test/test_source_encoding.py Lib/test/test_support.py Lib/test/test_threaded_import.py description: Issue #22390: Fix test_imp and test_import to remove created files diff -r 04147b0172d7 -r f9c8c4a22415 Lib/test/test_imp.py --- a/Lib/test/test_imp.py Wed Sep 17 23:24:39 2014 +0200 +++ b/Lib/test/test_imp.py Wed Sep 17 23:58:39 2014 +0200 @@ -198,6 +198,7 @@ class ImportTests(unittest.TestCase): support.unlink(temp_mod_name + ext) support.unlink(init_file_name + ext) support.rmtree(test_package_name) + support.rmtree('__pycache__') def test_issue9319(self): path = os.path.dirname(__file__) diff -r 04147b0172d7 -r f9c8c4a22415 Lib/test/test_import.py --- a/Lib/test/test_import.py Wed Sep 17 23:24:39 2014 +0200 +++ b/Lib/test/test_import.py Wed Sep 17 23:58:39 2014 +0200 @@ -1062,6 +1062,7 @@ class ImportTracebackTests(unittest.Test # Issue #11619: The Python parser and the import machinery must not # encode filenames, especially on Windows pyname = script_helper.make_script('', TESTFN_UNENCODABLE, 'pass') + self.addCleanup(test.support.unlink, pyname) name = pyname[:-3] script_helper.assert_python_ok("-c", "mod = __import__(%a)" % name, __isolated=False) diff -r 04147b0172d7 -r f9c8c4a22415 Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py Wed Sep 17 23:24:39 2014 +0200 +++ b/Lib/test/test_pdb.py Wed Sep 17 23:58:39 2014 +0200 @@ -916,6 +916,7 @@ class PdbTestCase(unittest.TestCase): with open(filename, 'w') as f: f.write(textwrap.dedent(script)) self.addCleanup(support.unlink, filename) + self.addCleanup(support.rmtree, '__pycache__') cmd = [sys.executable, '-m', 'pdb', filename] stdout = stderr = None with subprocess.Popen(cmd, stdout=subprocess.PIPE, diff -r 04147b0172d7 -r f9c8c4a22415 Lib/test/test_posix.py --- a/Lib/test/test_posix.py Wed Sep 17 23:24:39 2014 +0200 +++ b/Lib/test/test_posix.py Wed Sep 17 23:58:39 2014 +0200 @@ -1124,18 +1124,16 @@ class PosixTester(unittest.TestCase): """ Test functions that call path_error2(), providing two filenames in their exceptions. """ - for name in ("rename", "replace", "link", "symlink"): - function = getattr(os, name, None) - - if function: + for name in ("rename", "replace", "link"): + with self.subTest(function=name): + if not hasattr(os, name): + continue + function = getattr(os, name) for dst in ("noodly2", support.TESTFN): - try: + with self.assertRaises(OSError) as cm: function('doesnotexistfilename', dst) - except OSError as e: - self.assertIn("'doesnotexistfilename' -> '{}'".format(dst), str(e)) - break - else: - self.fail("No valid path_error2() test for os." + name) + self.assertIn("'doesnotexistfilename' -> '{}'".format(dst), + str(cm.exception)) class PosixGroupsTester(unittest.TestCase): diff -r 04147b0172d7 -r f9c8c4a22415 Lib/test/test_source_encoding.py --- a/Lib/test/test_source_encoding.py Wed Sep 17 23:24:39 2014 +0200 +++ b/Lib/test/test_source_encoding.py Wed Sep 17 23:58:39 2014 +0200 @@ -1,7 +1,7 @@ # -*- coding: koi8-r -*- import unittest -from test.support import TESTFN, unlink, unload +from test.support import TESTFN, unlink, unload, rmtree import importlib import os import sys @@ -129,6 +129,7 @@ class SourceEncodingTest(unittest.TestCa unlink(filename + "c") unlink(filename + "o") unload(TESTFN) + rmtree('__pycache__') def test_error_from_string(self): # See http://bugs.python.org/issue6289 diff -r 04147b0172d7 -r f9c8c4a22415 Lib/test/test_support.py --- a/Lib/test/test_support.py Wed Sep 17 23:24:39 2014 +0200 +++ b/Lib/test/test_support.py Wed Sep 17 23:58:39 2014 +0200 @@ -69,6 +69,7 @@ class TestSupport(unittest.TestCase): finally: del sys.path[0] support.unlink(mod_filename) + support.rmtree('__pycache__') def test_HOST(self): s = socket.socket() diff -r 04147b0172d7 -r f9c8c4a22415 Lib/test/test_threaded_import.py --- a/Lib/test/test_threaded_import.py Wed Sep 17 23:24:39 2014 +0200 +++ b/Lib/test/test_threaded_import.py Wed Sep 17 23:58:39 2014 +0200 @@ -13,7 +13,8 @@ import time import shutil import unittest from test.support import ( - verbose, import_module, run_unittest, TESTFN, reap_threads, forget, unlink) + verbose, import_module, run_unittest, TESTFN, reap_threads, + forget, unlink, rmtree) threading = import_module('threading') def task(N, done, done_tasks, errors): @@ -224,6 +225,7 @@ class ThreadedImportTests(unittest.TestC f.write(code.encode('utf-8')) self.addCleanup(unlink, filename) self.addCleanup(forget, TESTFN) + self.addCleanup(rmtree, '__pycache__') importlib.invalidate_caches() __import__(TESTFN)