From 8bac666b457ab10d3eb1029f3bdcc27b870bb967 Mon Sep 17 00:00:00 2001 From: vient Date: Wed, 1 Nov 2023 19:24:47 +0200 Subject: [PATCH] Fix missing non-zero return code from TEE'd pipe (#661) * Fix missing non-zero return code from TEE'd pipe * fix --- plumbum/commands/modifiers.py | 1 + tests/test_local.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plumbum/commands/modifiers.py b/plumbum/commands/modifiers.py index 98b3749f2..af59071a8 100644 --- a/plumbum/commands/modifiers.py +++ b/plumbum/commands/modifiers.py @@ -226,6 +226,7 @@ def __rand__(self, cmd): buf.append(data) + p.wait() # To get return code in p stdout = "".join([x.decode("utf-8") for x in outbuf]) stderr = "".join([x.decode("utf-8") for x in errbuf]) return p.returncode, stdout, stderr diff --git a/tests/test_local.py b/tests/test_local.py index 889624ab9..3b5eb514d 100644 --- a/tests/test_local.py +++ b/tests/test_local.py @@ -607,7 +607,7 @@ def test_iter_lines_line_timeout(self): @skip_on_windows def test_modifiers(self): - from plumbum.cmd import grep, ls + from plumbum.cmd import cat, grep, ls f = (ls["-a"] | grep["\\.py"]) & BG f.wait() @@ -615,11 +615,17 @@ def test_modifiers(self): command = ls["-a"] | grep["local"] command_false = ls["-a"] | grep["not_a_file_here"] + command_false_2 = command_false | cat command & FG assert command & TF assert not (command_false & TF) + assert not (command_false_2 & TF) assert command & RETCODE == 0 assert command_false & RETCODE == 1 + assert command_false_2 & RETCODE == 1 + assert (command & TEE)[0] == 0 + assert (command_false & TEE(retcode=None))[0] == 1 + assert (command_false_2 & TEE(retcode=None))[0] == 1 @skip_on_windows def test_tee_modifier(self, capfd):