diff options
author | Zackery Spytz <zspytz@gmail.com> | 2018-07-03 19:47:22 (GMT) |
---|---|---|
committer | Antoine Pitrou <pitrou@free.fr> | 2018-07-03 19:47:22 (GMT) |
commit | d8cba5d16f1333fd625726fc72e66afbd45b8d00 (patch) | |
tree | 6aa57f4d44036535b4cdf7895e92cd235a5b8f4f /Lib/test/test_gc.py | |
parent | 831c29721dcb1b768c6315a4b8a4059c4c97ee8b (diff) | |
download | cpython-d8cba5d16f1333fd625726fc72e66afbd45b8d00.zip cpython-d8cba5d16f1333fd625726fc72e66afbd45b8d00.tar.gz cpython-d8cba5d16f1333fd625726fc72e66afbd45b8d00.tar.bz2 |
bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918)
PyErr_Print() will not return when the exception is a SystemExit, so
decref the __main__ module object in that case.
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 904fc7d..8d806db 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1,7 +1,7 @@ import unittest from test.support import (verbose, refcount_test, run_unittest, strip_python_stderr, cpython_only, start_threads, - temp_dir, requires_type_collecting) + temp_dir, requires_type_collecting, TESTFN, unlink) from test.support.script_helper import assert_python_ok, make_script import sys @@ -708,6 +708,21 @@ class GCTests(unittest.TestCase): rc, out, err = assert_python_ok('-c', code) self.assertEqual(out.strip(), b'__del__ called') + @requires_type_collecting + def test_global_del_SystemExit(self): + code = """if 1: + class ClassWithDel: + def __del__(self): + print('__del__ called') + a = ClassWithDel() + a.link = a + raise SystemExit(0)""" + self.addCleanup(unlink, TESTFN) + with open(TESTFN, 'w') as script: + script.write(code) + rc, out, err = assert_python_ok(TESTFN) + self.assertEqual(out.strip(), b'__del__ called') + def test_get_stats(self): stats = gc.get_stats() self.assertEqual(len(stats), 3) |