gh-67224: Show source lines in tracebacks when using the -c option when running Python (#111200)

This commit is contained in:
Pablo Galindo Salgado 2023-10-26 15:17:28 +09:00 committed by GitHub
parent 3f84a19e62
commit 90a1b2859f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 104 additions and 36 deletions

View file

@ -684,6 +684,16 @@ class CmdLineTest(unittest.TestCase):
]
)
def test_source_lines_are_shown_when_running_source(self):
_, _, stderr = assert_python_failure("-c", "1/0")
expected_lines = [
b'Traceback (most recent call last):',
b' File "<string>", line 1, in <module>',
b' 1/0',
b' ~^~',
b'ZeroDivisionError: division by zero']
self.assertEqual(stderr.splitlines(), expected_lines)
def test_syntaxerror_does_not_crash(self):
script = "nonlocal x\n"
with os_helper.temp_dir() as script_dir: