diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-10-28 19:16:21 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-10-28 19:16:21 +0100 |
commit | c3408df66ec4dbebcbbfc283cebd9736d97f5f1c (patch) | |
tree | 1c63cd25bb30061e41410fc4014373104503c197 | |
parent | fe2feb2def06b6ee8e2818f1818a2b2743d917b1 (diff) | |
download | cpython-c3408df66ec4dbebcbbfc283cebd9736d97f5f1c.tar.gz |
Issue #19421: add an unit test for warnings.warn() during finalization
-rw-r--r-- | Lib/test/test_warnings.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index 464ff40d42..3c54c5a210 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -788,6 +788,25 @@ class BootstrapTest(unittest.TestCase): env=env) self.assertEqual(retcode, 0) +class FinalizationTest(unittest.TestCase): + def test_finalization(self): + # Issue #19421: warnings.warn() should not crash + # during Python finalization + code = """ +import warnings +warn = warnings.warn + +class A: + def __del__(self): + warn("test") + +a=A() + """ + rc, out, err = assert_python_ok("-c", code) + # note: "__main__" filename is not correct, it should be the name + # of the script + self.assertEqual(err, b'__main__:7: UserWarning: test') + def setUpModule(): py_warnings.onceregistry.clear() |