[Python-checkins] cpython: Issue #19421: add an unit test for warnings.warn() during finalization

victor.stinner python-checkins at python.org
Mon Oct 28 19:21:38 CET 2013


http://hg.python.org/cpython/rev/2d802765d31f
changeset:   86703:2d802765d31f
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Oct 28 19:16:21 2013 +0100
summary:
  Issue #19421: add an unit test for warnings.warn() during finalization

files:
  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
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -788,6 +788,25 @@
                 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()

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list