Skip to content

Commit

Permalink
pythongh-121973: Fix flaky test_pyrepl tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
colesbury committed Jul 22, 2024
1 parent 69f2dc5 commit d23344e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False
self.assertEqual(exit_code, 0)
for var, expected in expectations.items():
with self.subTest(var=var, expected=expected):
if m := re.search(rf"[\r\n]{var}=(.+?)[\r\n]", output):
if m := re.search(rf"[^{{]{var}=(.+?)[\r\n]", output):
self._assertMatchOK(var, expected, actual=m.group(1))
else:
self.fail(f"{var}= not found in output")
Expand Down Expand Up @@ -1126,4 +1126,4 @@ def run_repl(
except subprocess.TimeoutExpired:
process.kill()
exit_code = process.wait()
return "\n".join(output), exit_code
return "".join(output), exit_code

0 comments on commit d23344e

Please sign in to comment.