Skip to content

Commit d23344e

Browse files
committed
gh-121973: Fix flaky test_pyrepl tests
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.
1 parent 69f2dc5 commit d23344e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ 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:
995995
self.fail(f"{var}= not found in 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)