MCPcopy Index your code
hub / github.com/python/cpython / test_pep_765_warning

Method test_pep_765_warning

Lib/test/test_pyrepl/test_interact.py:280–301  ·  view source on GitHub ↗

Test that a SyntaxWarning emitted from the AST optimizer is only shown once in the REPL.

(self)

Source from the content-addressed store, hash-verified

278
279class TestWarnings(unittest.TestCase):
280 def test_pep_765_warning(self):
281 """
282 Test that a SyntaxWarning emitted from the
283 AST optimizer is only shown once in the REPL.
284 """
285 # gh-131927
286 console = InteractiveColoredConsole()
287 code = dedent("""\
288 def f():
289 try:
290 return 1
291 finally:
292 return 2
293 """)
294
295 with warnings.catch_warnings(record=True) as caught:
296 warnings.simplefilter("always")
297 console.runsource(code)
298
299 count = sum("'return' in a 'finally' block" in str(w.message)
300 for w in caught)
301 self.assertEqual(count, 1)

Callers

nothing calls this directly

Calls 5

runsourceMethod · 0.95
dedentFunction · 0.90
strFunction · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected