]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19421: add an unit test for warnings.warn() during finalization
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 28 Oct 2013 18:16:21 +0000 (19:16 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 28 Oct 2013 18:16:21 +0000 (19:16 +0100)
Lib/test/test_warnings.py

index 464ff40d42f8f19aa9d22f27bfb86e2f64f53d09..3c54c5a21003db729f935cef1f4c908a6b2c166a 100644 (file)
@@ -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()