From a3ae271d1ec2d392c1120655167b50070f788cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Tue, 5 Feb 2019 00:14:24 +0200 Subject: [PATCH] Bugfix aa-decode test: Get stderr correctly, don't ignore stderr contents Defining 'stderr = subprocess.STDOUT' as a default value for function did not work and the 'stderr' was always empty, thus also 'outerr' was always empty and not standard error contents was ever considered in any way. Best in fact was to remove excess function arguments as they were not even used and replace it with a simpler and less error prone structure. Even after reading 'stderr' correctly it did not help much as all tests used 'assertIn' which ignored excess output. Better replace the normal output with the error output if there ever was something, since stderr is most likely a serious thing and tests should stop on it. --- utils/test/test-aa-decode.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/utils/test/test-aa-decode.py b/utils/test/test-aa-decode.py index d9da7c374..96dfcfb48 100755 --- a/utils/test/test-aa-decode.py +++ b/utils/test/test-aa-decode.py @@ -28,23 +28,33 @@ def subprocess_setup(): # non-Python subprocesses expect. signal.signal(signal.SIGPIPE, signal.SIG_DFL) -def cmd(command, input = None, stderr = subprocess.STDOUT, stdout = subprocess.PIPE, stdin = None, timeout = None): +# Define only arguments that are actually ever used: command and stdin +def cmd(command, stdin=None): '''Try to execute given command (array) and return its stdout, or return a textual error if it failed.''' try: - sp = subprocess.Popen(command, stdin=stdin, stdout=stdout, stderr=stderr, close_fds=True, preexec_fn=subprocess_setup) + sp = subprocess.Popen( + command, + stdin=stdin, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + close_fds=True, + preexec_fn=subprocess_setup + ) except OSError as e: return [127, str(e)] - out, outerr = sp.communicate(input) - # Handle redirection of stdout - if out == None: - out = b'' - # Handle redirection of stderr - if outerr == None: - outerr = b'' - return [sp.returncode, out.decode('utf-8') + outerr.decode('utf-8')] + stdout, stderr = sp.communicate(input) + + # If there was some error output, show that instead of stdout to ensure + # test fails and does not mask potentially major warnings and errors. + if stderr: + out = stderr + else: + out = stdout + + return [sp.returncode, out.decode('utf-8')] def mkstemp_fill(contents, suffix='', prefix='tst-aadecode-', dir=None):