Test that a SyntaxWarning emitted from the AST optimizer is only shown once in the REPL.
(self)
| 278 | |
| 279 | class 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) |
nothing calls this directly
no test coverage detected