Skip to content

Commit 039fbe7

Browse files
author
Juhani Puurula
committed
Fix to unit test losing process output due to timing issue
1 parent 442cbba commit 039fbe7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

UNITTESTS/unit_test/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ def execute_program(args, error_msg="An error occurred!", success_msg=None):
5151
stdout=subprocess.PIPE,
5252
stderr=subprocess.STDOUT)
5353

54+
# Output is stripped to remove newline character. logging adds its own
55+
# so we avoid double newlines.
56+
# Because the process can terminate before the loop has read all lines,
57+
# we read the output remnant just in case. Otherwise we lose it.
5458
while process.poll() is None:
55-
logging.info(process.stdout.readline().decode("utf8"))
59+
logging.info(process.stdout.readline().decode('utf8').rstrip('\n'))
60+
logging.info(process.stdout.read().decode('utf8').rstrip('\n'))
5661

5762
retcode = process.wait()
5863

0 commit comments

Comments
 (0)