Skip to content

Commit 0d265e3

Browse files
committed
Change the test a little bit.
1 parent 696b021 commit 0d265e3

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

Lib/test/test_sys.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,24 @@ def check_exit_message(code, expected, **env_vars):
274274

275275
@support.requires_subprocess()
276276
def test_exit_codes_under_repl(self):
277+
# GH-129900: SystemExit, or things that raised it, didn't
278+
# get their return code propagated by the REPL
277279
import tempfile
278280

279-
cases = [
280-
("exit", 123),
281-
("exit", 0),
282-
("__import__('sys').exit", 123),
283-
("__import__('sys').exit", 0)
281+
exit_ways = [
282+
"exit",
283+
"__import__('sys').exit",
284+
"raise SystemExit"
284285
]
285286

286-
for exitfunc, return_code in cases:
287-
with self.subTest(exitfunc=exitfunc, return_code=return_code):
288-
with tempfile.TemporaryFile("w+") as stdin:
289-
stdin.write(f"{exitfunc}({return_code})\n")
290-
stdin.seek(0)
291-
proc = subprocess.run([sys.executable], stdin=stdin)
292-
self.assertEqual(proc.returncode, return_code)
287+
for exitfunc in exit_ways:
288+
for return_code in (0, 123):
289+
with self.subTest(exitfunc=exitfunc, return_code=return_code):
290+
with tempfile.TemporaryFile("w+") as stdin:
291+
stdin.write(f"{exitfunc}({return_code})\n")
292+
stdin.seek(0)
293+
proc = subprocess.run([sys.executable], stdin=stdin)
294+
self.assertEqual(proc.returncode, return_code)
293295

294296
def test_getdefaultencoding(self):
295297
self.assertRaises(TypeError, sys.getdefaultencoding, 42)

0 commit comments

Comments
 (0)