Skip to content

Commit 214b430

Browse files
miss-islingtoncolesburyambv
authored
[3.13] pythongh-121973: Fix flaky test_pyrepl tests (pythonGH-122140) (pythonGH-122173)
This fixes the flakiness in: * test_inspect_keeps_globals_from_inspected_file * test_inspect_keeps_globals_from_inspected_module The output already includes newlines. Adding newlines for every entry in the output list introduces non-determinism because it added '\n' in places where stdout is flushed or some buffer becomes full. The regex also needed to be updated because pyrepl includes control characters -- the visible output on each line doesn't immediately follow a newline character. (cherry picked from commit 2c1b1e7) Co-authored-by: Sam Gross <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent ae9e02c commit 214b430

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Lib/test/test_pyrepl/test_pyrepl.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
963963
mod = blue / "calx.py"
964964
mod.write_text("FOO = 42", encoding="utf-8")
965965
commands = [
966-
"print(f'{" + var + "=}')" for var in expectations
966+
"print(f'^{" + var + "=}')" for var in expectations
967967
] + ["exit()"]
968968
if as_file and as_module:
969969
self.fail("as_file and as_module are mutually exclusive")
@@ -989,10 +989,10 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
989989
self.assertEqual(exit_code, 0)
990990
for var, expected in expectations.items():
991991
with self.subTest(var=var, expected=expected):
992-
if m := re.search(rf"[\r\n]{var}=(.+?)[\r\n]", output):
992+
if m := re.search(rf"\^{var}=(.+?)[\r\n]", output):
993993
self._assertMatchOK(var, expected, actual=m.group(1))
994994
else:
995-
self.fail(f"{var}= not found in output")
995+
self.fail(f"{var}= not found in output: {output!r}\n\n{output}")
996996

997997
self.assertNotIn("Exception", output)
998998
self.assertNotIn("Traceback", output)
@@ -1126,4 +1126,4 @@ def run_repl(
11261126
except subprocess.TimeoutExpired:
11271127
process.kill()
11281128
exit_code = process.wait()
1129-
return "\n".join(output), exit_code
1129+
return "".join(output), exit_code

0 commit comments

Comments
 (0)