https://github.com/python/cpython/commit/214b430fafc49f9977c251178c61794b4caad347 commit: 214b430fafc49f9977c251178c61794b4caad347 branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: ambv <luk...@langa.pl> date: 2024-07-23T15:57:24+02:00 summary:
[3.13] gh-121973: Fix flaky test_pyrepl tests (GH-122140) (GH-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 2c1b1e7a07eba0138b9858c6f2bea3cae9af0808) Co-authored-by: Sam Gross <colesb...@gmail.com> Co-authored-by: Ćukasz Langa <luk...@langa.pl> files: M Lib/test/test_pyrepl/test_pyrepl.py diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index e3feeeb76f11d6..3a1bacef8a1756 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -963,7 +963,7 @@ def _run_repl_globals_test(self, expectations, *, as_file=False, as_module=False mod = blue / "calx.py" mod.write_text("FOO = 42", encoding="utf-8") commands = [ - "print(f'{" + var + "=}')" for var in expectations + "print(f'^{" + var + "=}')" for var in expectations ] + ["exit()"] if as_file and as_module: 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 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") + self.fail(f"{var}= not found in output: {output!r}\n\n{output}") self.assertNotIn("Exception", output) self.assertNotIn("Traceback", output) @@ -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 _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com