Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d1b4899

Browse files
committed
Issue #19421: add an unit test for warnings.warn() during finalization
1 parent ce5f4fb commit d1b4899

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lib/test/test_warnings.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,25 @@ def test_issue_8766(self):
788788
env=env)
789789
self.assertEqual(retcode, 0)
790790

791+
class FinalizationTest(unittest.TestCase):
792+
def test_finalization(self):
793+
# Issue #19421: warnings.warn() should not crash
794+
# during Python finalization
795+
code = """
796+
import warnings
797+
warn = warnings.warn
798+
799+
class A:
800+
def __del__(self):
801+
warn("test")
802+
803+
a=A()
804+
"""
805+
rc, out, err = assert_python_ok("-c", code)
806+
# note: "__main__" filename is not correct, it should be the name
807+
# of the script
808+
self.assertEqual(err, b'__main__:7: UserWarning: test')
809+
791810

792811
def setUpModule():
793812
py_warnings.onceregistry.clear()

0 commit comments

Comments
 (0)