diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py index d3241918b68..8eb56f6c057 100644 --- a/Lib/test/test_imp.py +++ b/Lib/test/test_imp.py @@ -278,13 +278,11 @@ class ImportTests(unittest.TestCase): @unittest.skipIf(sys.dont_write_bytecode, "test meaningful only when writing bytecode") def test_bug7732(self): - source = support.TESTFN + '.py' - os.mkdir(source) - try: + with support.temp_cwd(): + source = support.TESTFN + '.py' + os.mkdir(source) self.assertRaisesRegex(ImportError, '^No module', imp.find_module, support.TESTFN, ["."]) - finally: - os.rmdir(source) class ReloadTests(unittest.TestCase):