Skip to content

Commit f1f1605

Browse files
author
MarcoFalke
committed
Merge #10703: [tests] Allow tests to pass when stderr is non-empty
d64ac3f [tests] Allow tests to pass when stderr is non-empty (Jonas Schnelli) Pull request description: Resurrect #10241 with nits addressed Not sure how much people want this. Would be useful for functional tests which cause bitcoind to print to stderr. Tree-SHA512: 28caccf7818fb3ed5a38caef7f77161b1678aa9b8fd12c2d1e76032f409f0d33c40f7ac91e0c8d908df4a44fd01cf97d657a08bae50c6ff17d07f5b2e20c3a6e
2 parents 1caafa6 + d64ac3f commit f1f1605

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

test/functional/test_runner.py

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
import re
2828
import logging
2929

30-
# Formatting. Default colors to empty strings.
31-
BOLD, BLUE, RED, GREY = ("", ""), ("", ""), ("", ""), ("", "")
30+
# Formatting.
3231
try:
3332
# Make sure python thinks it can write unicode to its stdout
3433
"\u2713".encode("utf_8").decode(sys.stdout.encoding)
@@ -40,17 +39,28 @@
4039
CROSS = "x "
4140
CIRCLE = "o "
4241

42+
# Default colors to empty strings.
43+
BOLD, BLUE, RED, GREY, MAGENTA = [("", "")] * 5
4344
if os.name == 'posix':
4445
# primitive formatting on supported
4546
# terminal via ANSI escape sequences:
4647
BOLD = ('\033[0m', '\033[1m')
47-
BLUE = ('\033[0m', '\033[0;34m')
48-
RED = ('\033[0m', '\033[0;31m')
4948
GREY = ('\033[0m', '\033[1;30m')
49+
RED = ('\033[0m', '\033[0;31m')
50+
BLUE = ('\033[0m', '\033[0;34m')
51+
MAGENTA = ('\033[0m', '\033[0;35m')
5052

5153
TEST_EXIT_PASSED = 0
5254
TEST_EXIT_SKIPPED = 77
5355

56+
STATUS_PASSED = "Passed"
57+
STATUS_PASSED_WITH_WARNINGS = "Passed with warnings"
58+
STATUS_SKIPPED = "Skipped"
59+
STATUS_FAILED = "Failed"
60+
STATUSES = [STATUS_PASSED, STATUS_PASSED_WITH_WARNINGS, STATUS_SKIPPED, STATUS_FAILED]
61+
62+
STATUS_MAX_LEN = max([len(st) for st in STATUSES])
63+
5464
BASE_SCRIPTS= [
5565
# Scripts that are run by the travis build process.
5666
# Longest test should go first, to favor running tests in parallel
@@ -307,9 +317,11 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
307317
test_result, stdout, stderr = job_queue.get_next()
308318
test_results.append(test_result)
309319

310-
if test_result.status == "Passed":
320+
if test_result.status == STATUS_PASSED:
311321
logging.debug("\n%s%s%s passed, Duration: %s s" % (BOLD[1], test_result.name, BOLD[0], test_result.time))
312-
elif test_result.status == "Skipped":
322+
elif test_result.status == STATUS_PASSED_WITH_WARNINGS:
323+
logging.debug("\n%s%s%s passed with warnings, Duration: %s s" % (BOLD[1], test_result.name, BOLD[0], test_result.time))
324+
elif test_result.status == STATUS_SKIPPED:
313325
logging.debug("\n%s%s%s skipped" % (BOLD[1], test_result.name, BOLD[0]))
314326
else:
315327
print("\n%s%s%s failed, Duration: %s s\n" % (BOLD[1], test_result.name, BOLD[0], test_result.time))
@@ -333,7 +345,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
333345
sys.exit(not all_passed)
334346

335347
def print_results(test_results, max_len_name, runtime):
336-
results = "\n" + BOLD[1] + "%s | %s | %s\n\n" % ("TEST".ljust(max_len_name), "STATUS ", "DURATION") + BOLD[0]
348+
results = "\n" + BOLD[1] + "%s | %s | %s\n\n" % ("TEST".ljust(max_len_name), " STATUS".ljust(STATUS_MAX_LEN + 2), "DURATION") + BOLD[0]
337349

338350
test_results.sort(key=lambda result: result.name.lower())
339351
all_passed = True
@@ -346,7 +358,7 @@ def print_results(test_results, max_len_name, runtime):
346358
results += str(test_result)
347359

348360
status = TICK + "Passed" if all_passed else CROSS + "Failed"
349-
results += BOLD[1] + "\n%s | %s | %s s (accumulated) \n" % ("ALL".ljust(max_len_name), status.ljust(9), time_sum) + BOLD[0]
361+
results += BOLD[1] + "\n%s | %s | %s s (accumulated) \n" % ("ALL".ljust(max_len_name), status.ljust(STATUS_MAX_LEN + 2), time_sum) + BOLD[0]
350362
results += "Runtime: %s s\n" % (runtime)
351363
print(results)
352364

@@ -404,11 +416,13 @@ def get_next(self):
404416
[stdout, stderr] = [l.read().decode('utf-8') for l in (log_out, log_err)]
405417
log_out.close(), log_err.close()
406418
if proc.returncode == TEST_EXIT_PASSED and stderr == "":
407-
status = "Passed"
419+
status = STATUS_PASSED
420+
elif proc.returncode == TEST_EXIT_PASSED:
421+
status = STATUS_PASSED_WITH_WARNINGS
408422
elif proc.returncode == TEST_EXIT_SKIPPED:
409-
status = "Skipped"
423+
status = STATUS_SKIPPED
410424
else:
411-
status = "Failed"
425+
status = STATUS_FAILED
412426
self.num_running -= 1
413427
self.jobs.remove(j)
414428

@@ -423,17 +437,20 @@ def __init__(self, name, status, time):
423437
self.padding = 0
424438

425439
def __repr__(self):
426-
if self.status == "Passed":
440+
if self.status == STATUS_PASSED:
427441
color = BLUE
428442
glyph = TICK
429-
elif self.status == "Failed":
430-
color = RED
431-
glyph = CROSS
432-
elif self.status == "Skipped":
443+
if self.status == STATUS_PASSED_WITH_WARNINGS:
444+
color = MAGENTA
445+
glyph = TICK
446+
elif self.status == STATUS_SKIPPED:
433447
color = GREY
434448
glyph = CIRCLE
449+
elif self.status == STATUS_FAILED:
450+
color = RED
451+
glyph = CROSS
435452

436-
return color[1] + "%s | %s%s | %s s\n" % (self.name.ljust(self.padding), glyph, self.status.ljust(7), self.time) + color[0]
453+
return color[1] + "%s | %s%s | %s s\n" % (self.name.ljust(self.padding), glyph, self.status.ljust(STATUS_MAX_LEN), self.time) + color[0]
437454

438455
@property
439456
def was_successful(self):

0 commit comments

Comments
 (0)