Kaydet (Commit) 1426a99d authored tarafından Benjamin Peterson's avatar Benjamin Peterson

simplify cleanup of test_replace_parent_in_sys_modules (closes #28862)

üst 2df5adb9
...@@ -400,20 +400,19 @@ class ImportTests(unittest.TestCase): ...@@ -400,20 +400,19 @@ class ImportTests(unittest.TestCase):
def test_replace_parent_in_sys_modules(self): def test_replace_parent_in_sys_modules(self):
dir_name = os.path.abspath(TESTFN) dir_name = os.path.abspath(TESTFN)
os.mkdir(dir_name) os.mkdir(dir_name)
try: self.addCleanup(rmtree, dir_name)
pkg_dir = os.path.join(dir_name, 'sa') pkg_dir = os.path.join(dir_name, 'sa')
os.mkdir(pkg_dir) os.mkdir(pkg_dir)
with open(os.path.join(pkg_dir, '__init__.py'), 'w') as init_file: with open(os.path.join(pkg_dir, '__init__.py'), 'w') as init_file:
init_file.write("import v1") init_file.write("import v1")
with open(os.path.join(pkg_dir, 'v1.py'), 'w') as v1_file: with open(os.path.join(pkg_dir, 'v1.py'), 'w') as v1_file:
v1_file.write("import sys;" v1_file.write("import sys;"
"sys.modules['sa'] = sys.modules[__name__];" "sys.modules['sa'] = sys.modules[__name__];"
"import sa") "import sa")
sys.path.insert(0, dir_name) sys.path.insert(0, dir_name)
# a segfault means the test failed! self.addCleanup(sys.path.pop, 0)
import sa # a segfault means the test failed!
finally: import sa
rmtree(dir_name)
def test_fromlist_type(self): def test_fromlist_type(self):
with self.assertRaises(TypeError) as cm: with self.assertRaises(TypeError) as cm:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment