gh-128231: Use runcode() return value for failing early (GH-129488)

This commit is contained in:
Bartosz Sławecki 2025-02-24 15:50:13 +01:00 committed by GitHub
parent 9f25c1f012
commit 7ed3dc6392
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 40 additions and 3 deletions

View file

@ -53,6 +53,19 @@ def test_multiple_statements_output(self):
self.assertFalse(more)
self.assertEqual(f.getvalue(), "1\n")
@force_not_colorized
def test_multiple_statements_fail_early(self):
console = InteractiveColoredConsole()
code = dedent("""\
raise Exception('foobar')
print('spam&eggs')
""")
f = io.StringIO()
with contextlib.redirect_stderr(f):
console.runsource(code)
self.assertIn('Exception: foobar', f.getvalue())
self.assertNotIn('spam&eggs', f.getvalue())
def test_empty(self):
namespace = {}
code = ""