Skip to content

Commit fa43c4f

Browse files
author
MarcoFalke
committed
test: Print CompletedProcess object on error
1 parent 5fb9455 commit fa43c4f

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

test/util/test_runner.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,11 @@ def bctest(testDir, testObj, buildenv):
8383
execrun = [execprog] + execargs
8484

8585
# Read the input data (if there is any)
86-
stdinCfg = None
8786
inputData = None
8887
if "input" in testObj:
8988
filename = os.path.join(testDir, testObj["input"])
9089
with open(filename, encoding="utf8") as f:
9190
inputData = f.read()
92-
stdinCfg = subprocess.PIPE
9391

9492
# Read the expected output data (if there is any)
9593
outputFn = None
@@ -112,9 +110,8 @@ def bctest(testDir, testObj, buildenv):
112110
raise Exception
113111

114112
# Run the test
115-
proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
116113
try:
117-
outs = proc.communicate(input=inputData)
114+
res = subprocess.run(execrun, capture_output=True, text=True, input=inputData)
118115
except OSError:
119116
logging.error("OSError, Failed to execute " + execprog)
120117
raise
@@ -123,9 +120,9 @@ def bctest(testDir, testObj, buildenv):
123120
data_mismatch, formatting_mismatch = False, False
124121
# Parse command output and expected output
125122
try:
126-
a_parsed = parse_output(outs[0], outputType)
123+
a_parsed = parse_output(res.stdout, outputType)
127124
except Exception as e:
128-
logging.error('Error parsing command output as %s: %s' % (outputType, e))
125+
logging.error(f"Error parsing command output as {outputType}: '{str(e)}'; res: {str(res)}")
129126
raise
130127
try:
131128
b_parsed = parse_output(outputData, outputType)
@@ -134,13 +131,13 @@ def bctest(testDir, testObj, buildenv):
134131
raise
135132
# Compare data
136133
if a_parsed != b_parsed:
137-
logging.error("Output data mismatch for " + outputFn + " (format " + outputType + ")")
134+
logging.error(f"Output data mismatch for {outputFn} (format {outputType}); res: {str(res)}")
138135
data_mismatch = True
139136
# Compare formatting
140-
if outs[0] != outputData:
141-
error_message = "Output formatting mismatch for " + outputFn + ":\n"
137+
if res.stdout != outputData:
138+
error_message = f"Output formatting mismatch for {outputFn}:\nres: {str(res)}\n"
142139
error_message += "".join(difflib.context_diff(outputData.splitlines(True),
143-
outs[0].splitlines(True),
140+
res.stdout.splitlines(True),
144141
fromfile=outputFn,
145142
tofile="returned"))
146143
logging.error(error_message)
@@ -152,8 +149,8 @@ def bctest(testDir, testObj, buildenv):
152149
wantRC = 0
153150
if "return_code" in testObj:
154151
wantRC = testObj['return_code']
155-
if proc.returncode != wantRC:
156-
logging.error("Return code mismatch for " + outputFn)
152+
if res.returncode != wantRC:
153+
logging.error(f"Return code mismatch for {outputFn}; res: {str(res)}")
157154
raise Exception
158155

159156
if "error_txt" in testObj:
@@ -164,8 +161,8 @@ def bctest(testDir, testObj, buildenv):
164161
# emits DISPLAY errors when running as a windows application on
165162
# linux through wine. Just assert that the expected error text appears
166163
# somewhere in stderr.
167-
if want_error not in outs[1]:
168-
logging.error("Error mismatch:\n" + "Expected: " + want_error + "\nReceived: " + outs[1].rstrip())
164+
if want_error not in res.stderr:
165+
logging.error(f"Error mismatch:\nExpected: {want_error}\nReceived: {res.stderr.rstrip()}\nres: {str(res)}")
169166
raise Exception
170167

171168
def parse_output(a, fmt):

0 commit comments

Comments
 (0)