diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-12-14 23:06:25 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-12-14 23:06:25 (GMT) |
commit | ce4b170c5a6ab03af66331871f827fb021cebe18 (patch) | |
tree | 520ad32eac01352bf8249cb8b4338218e41a33b1 /Lib | |
parent | 95333e3aa989c727b7a13ad32c1d169f70bd57ef (diff) | |
download | cpython-ce4b170c5a6ab03af66331871f827fb021cebe18.zip cpython-ce4b170c5a6ab03af66331871f827fb021cebe18.tar.gz cpython-ce4b170c5a6ab03af66331871f827fb021cebe18.tar.bz2 |
#4236: avoid possible Fatal Error when import is called from __del__
Patch by Simon Cross, crasher test code by Martin von Löwis.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_import.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py index 02f56e6..cf17c96 100644 --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -9,11 +9,13 @@ import random import stat import sys import unittest +import textwrap from test.support import ( EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython, make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask, unlink, unload) +from test import script_helper def remove_files(name): @@ -284,6 +286,17 @@ class ImportTests(unittest.TestCase): self.assertEqual("Import by filename is not supported.", c.exception.args[0]) + def test_import_in_del_does_not_crash(self): + # Issue 4236 + testfn = script_helper.make_script('', TESTFN, textwrap.dedent("""\ + import sys + class C: + def __del__(self): + import imp + sys.argv.insert(0, C()) + """)) + script_helper.assert_python_ok(testfn) + class PycRewritingTests(unittest.TestCase): # Test that the `co_filename` attribute on code objects always points |