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):
--- /dev/null
+Compiler warnings originating from the same module and line number are now
+only emitted once, matching the behaviour of warnings emitted from user
+code. This can also be configured with :mod:`warnings` filters.