diff -r e4dd5d700ef3 Lib/test/test_import.py --- a/Lib/test/test_import.py Sat Dec 03 12:39:10 2016 -0800 +++ b/Lib/test/test_import.py Sat Dec 03 23:42:23 2016 +0200 @@ -12,7 +12,8 @@ import textwrap import shutil from test.test_support import (unlink, TESTFN, unload, run_unittest, rmtree, - is_jython, check_warnings, EnvironmentVarGuard) + is_jython, check_warnings, EnvironmentVarGuard, + swap_attr) from test import symlink_support from test import script_helper @@ -409,9 +410,12 @@ class ImportTests(unittest.TestCase): v1_file.write("import sys;" "sys.modules['sa'] = sys.modules[__name__];" "import sa") - sys.path.insert(0, dir_name) - # a segfault means the test failed! - import sa + try: + sys.path.insert(0, dir_name) + # a segfault means the test failed! + import sa + finally: + sys.path.pop(0) finally: rmtree(dir_name)