From bae36143f0860859dde19874ebcb7a1ac6b51e86 Mon Sep 17 00:00:00 2001 From: Teddy Ni Date: Sat, 16 May 2026 14:05:58 -0700 Subject: [PATCH 1/3] Make BrokenPipeError test deterministic. This test seems to be flaky (albeit rarely). We can try to make it deterministic by writing more data during the test to reliably trigger BrokenPipeError. --- tests/test_console.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/test_console.py b/tests/test_console.py index e52c1b3633..077242c54d 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -1006,17 +1006,30 @@ def test_reenable_highlighting() -> None: @pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows") def test_brokenpipeerror() -> None: """Test BrokenPipe works as expected.""" - which_py, which_head = (["which", cmd] for cmd in ("python", "head")) - rich_cmd = "python -m rich".split() - for cmd in [which_py, which_head, rich_cmd]: - check = subprocess.run(cmd).returncode - if check != 0: - return # Only test on suitable Unix platforms - head_cmd = "head -1".split() - proc1 = subprocess.Popen(rich_cmd, stdout=subprocess.PIPE) - proc2 = subprocess.Popen(head_cmd, stdin=proc1.stdout, stdout=subprocess.PIPE) + + # We write enough output to hopefully keep the writing process busy and give + # enough time for the reading process to exist, creating a BrokenPipeError. + writer = ( + "from rich.console import Console\n" + "console = Console(force_terminal=True, width=240)\n" + "payload = 'X' * 200\n" + "for index in range(10000):\n" + " console.print(f'{index:06d} {payload}')\n" + ) + reader = "import sys; sys.stdin.buffer.read(1)" + proc1 = subprocess.Popen( + [sys.executable, "-c", writer], + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + ) + proc2 = subprocess.Popen( + [sys.executable, "-c", reader], + stdin=proc1.stdout, + stdout=subprocess.PIPE, + stderr=subprocess.DEVNULL, + ) proc1.stdout.close() - output, _ = proc2.communicate() + proc2.communicate() proc1.wait() proc2.wait() assert proc1.returncode == 1 From 2a98d8e7bb100ba59e8221ca2cd0449283224d12 Mon Sep 17 00:00:00 2001 From: Teddy Ni <3806110+tjni@users.noreply.github.com> Date: Sun, 17 May 2026 16:03:56 -0700 Subject: [PATCH 2/3] Add myself to CONTRIBUTORS.md. --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 2155a42a4d..60dfb4fd27 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -48,6 +48,7 @@ The following people have contributed to the development of Rich: - [Paul McGuire](https://github.com/ptmcg) - [Antony Milne](https://github.com/AntonyMilneQB) - [Michael Milton](https://github.com/multimeric) +- [Theodore Ni](https://github.com/tjni) - [Martina Oefelein](https://github.com/oefe) - [Joel Ostblom](https://github.com/joelostblom) - [Nathan Page](https://github.com/nathanrpage97) From 8025965a538d3f146969f368fb5f4b20bc59f7ba Mon Sep 17 00:00:00 2001 From: Teddy Ni <3806110+tjni@users.noreply.github.com> Date: Sun, 17 May 2026 16:19:26 -0700 Subject: [PATCH 3/3] Fix typo in a comment I wrote. --- tests/test_console.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_console.py b/tests/test_console.py index 077242c54d..8165f177f2 100644 --- a/tests/test_console.py +++ b/tests/test_console.py @@ -1008,7 +1008,7 @@ def test_brokenpipeerror() -> None: """Test BrokenPipe works as expected.""" # We write enough output to hopefully keep the writing process busy and give - # enough time for the reading process to exist, creating a BrokenPipeError. + # enough time for the reading process to exit, creating a BrokenPipeError. writer = ( "from rich.console import Console\n" "console = Console(force_terminal=True, width=240)\n"