mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-132435: Test syntax warnings in a finally block (GH-132436)
This commit is contained in:
parent
fc7e4e7bbd
commit
887eabc5a7
2 changed files with 23 additions and 0 deletions
|
@ -1664,6 +1664,26 @@ class TestSpecifics(unittest.TestCase):
|
|||
|
||||
self.assertEqual(len(caught), 2)
|
||||
|
||||
def test_compile_warning_in_finally(self):
|
||||
# Ensure that warnings inside finally blocks are
|
||||
# only emitted once despite the block being
|
||||
# compiled twice (for normal execution and for
|
||||
# exception handling).
|
||||
source = textwrap.dedent("""
|
||||
try:
|
||||
pass
|
||||
finally:
|
||||
1 is 1
|
||||
""")
|
||||
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("default")
|
||||
compile(source, '<stdin>', 'exec')
|
||||
|
||||
self.assertEqual(len(caught), 1)
|
||||
self.assertEqual(caught[0].category, SyntaxWarning)
|
||||
self.assertIn("\"is\" with 'int' literal", str(caught[0].message))
|
||||
|
||||
class TestBooleanExpression(unittest.TestCase):
|
||||
class Value:
|
||||
def __init__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue