aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerge-script <fanquake@gmail.com>2024-10-16 14:50:49 +0100
committermerge-script <fanquake@gmail.com>2024-10-16 14:50:49 +0100
commit21e2f06a1cc34667572bbe9e4654fc3ec6184646 (patch)
treef0e191490c7b21311b16a3ff32b3842e2548eb08
parentdea9fb9a8b8fe9426be465f61d9e4540e888c2fc (diff)
parentfa43c4f93ca5b40734ec9b3ff91b74acf3ed7cf2 (diff)
Merge bitcoin/bitcoin#31067: test: Print CompletedProcess object on error
fa43c4f93ca5b40734ec9b3ff91b74acf3ed7cf2 test: Print CompletedProcess object on error (MarcoFalke) Pull request description: It would be good to know the output on `Error parsing command output`. Otherwise test failures are meaningless: https://github.com/bitcoin/bitcoin/issues/30792#issuecomment-2325911157 Fix it by just printing the full `CompletedProcess` object. Also, use the modern `subprocess.run` to simplify the code. ACKs for top commit: BrandonOdiwuor: Code Review ACK fa43c4f93ca5b40734ec9b3ff91b74acf3ed7cf2 laanwj: This contains some useful information, so ACK fa43c4f93ca5b40734ec9b3ff91b74acf3ed7cf2 Tree-SHA512: ae7c1cb1f48af2a6feae6d1a5a967c0720f6c6675c1ce20ace7cac18c00f3d4069b8abcc58204855e92ff5303158b9a942bab3b71acae0737768d941a5773c91
-rwxr-xr-xtest/util/test_runner.py25
1 files changed, 11 insertions, 14 deletions
diff --git a/test/util/test_runner.py b/test/util/test_runner.py
index e4a77d53d6..cac184ca30 100755
--- a/test/util/test_runner.py
+++ b/test/util/test_runner.py
@@ -83,13 +83,11 @@ def bctest(testDir, testObj, buildenv):
execrun = [execprog] + execargs
# Read the input data (if there is any)
- stdinCfg = None
inputData = None
if "input" in testObj:
filename = os.path.join(testDir, testObj["input"])
with open(filename, encoding="utf8") as f:
inputData = f.read()
- stdinCfg = subprocess.PIPE
# Read the expected output data (if there is any)
outputFn = None
@@ -112,9 +110,8 @@ def bctest(testDir, testObj, buildenv):
raise Exception
# Run the test
- proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
try:
- outs = proc.communicate(input=inputData)
+ res = subprocess.run(execrun, capture_output=True, text=True, input=inputData)
except OSError:
logging.error("OSError, Failed to execute " + execprog)
raise
@@ -123,9 +120,9 @@ def bctest(testDir, testObj, buildenv):
data_mismatch, formatting_mismatch = False, False
# Parse command output and expected output
try:
- a_parsed = parse_output(outs[0], outputType)
+ a_parsed = parse_output(res.stdout, outputType)
except Exception as e:
- logging.error('Error parsing command output as %s: %s' % (outputType, e))
+ logging.error(f"Error parsing command output as {outputType}: '{str(e)}'; res: {str(res)}")
raise
try:
b_parsed = parse_output(outputData, outputType)
@@ -134,13 +131,13 @@ def bctest(testDir, testObj, buildenv):
raise
# Compare data
if a_parsed != b_parsed:
- logging.error("Output data mismatch for " + outputFn + " (format " + outputType + ")")
+ logging.error(f"Output data mismatch for {outputFn} (format {outputType}); res: {str(res)}")
data_mismatch = True
# Compare formatting
- if outs[0] != outputData:
- error_message = "Output formatting mismatch for " + outputFn + ":\n"
+ if res.stdout != outputData:
+ error_message = f"Output formatting mismatch for {outputFn}:\nres: {str(res)}\n"
error_message += "".join(difflib.context_diff(outputData.splitlines(True),
- outs[0].splitlines(True),
+ res.stdout.splitlines(True),
fromfile=outputFn,
tofile="returned"))
logging.error(error_message)
@@ -152,8 +149,8 @@ def bctest(testDir, testObj, buildenv):
wantRC = 0
if "return_code" in testObj:
wantRC = testObj['return_code']
- if proc.returncode != wantRC:
- logging.error("Return code mismatch for " + outputFn)
+ if res.returncode != wantRC:
+ logging.error(f"Return code mismatch for {outputFn}; res: {str(res)}")
raise Exception
if "error_txt" in testObj:
@@ -164,8 +161,8 @@ def bctest(testDir, testObj, buildenv):
# emits DISPLAY errors when running as a windows application on
# linux through wine. Just assert that the expected error text appears
# somewhere in stderr.
- if want_error not in outs[1]:
- logging.error("Error mismatch:\n" + "Expected: " + want_error + "\nReceived: " + outs[1].rstrip())
+ if want_error not in res.stderr:
+ logging.error(f"Error mismatch:\nExpected: {want_error}\nReceived: {res.stderr.rstrip()}\nres: {str(res)}")
raise Exception
def parse_output(a, fmt):