Skip to content

Commit 232b666

Browse files
committed
Allow test cases to be skipped
Currently, functional test cases can either pass or fail. There are occasions when it is helpful to skip tests, for example if the system they are running on does not meet the requirements for the test. The rest of the test suite can run without being marked as a failure. This commit adds framework for tests to skip if their requirements aren't met.
1 parent 02d64bd commit 232b666

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
)
2929
from .authproxy import JSONRPCException
3030

31-
3231
class BitcoinTestFramework(object):
3332

33+
TEST_EXIT_PASSED = 0
34+
TEST_EXIT_FAILED = 1
35+
TEST_EXIT_SKIPPED = 77
36+
3437
def __init__(self):
3538
self.num_nodes = 4
3639
self.setup_clean_chain = False
@@ -183,11 +186,11 @@ def main(self):
183186
print("".join(deque(open(f), MAX_LINES_TO_PRINT)))
184187
if success:
185188
self.log.info("Tests successful")
186-
sys.exit(0)
189+
sys.exit(self.TEST_EXIT_PASSED)
187190
else:
188191
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir)
189192
logging.shutdown()
190-
sys.exit(1)
193+
sys.exit(self.TEST_EXIT_FAILED)
191194

192195
def _start_logging(self):
193196
# Add logger and logging handlers

test/functional/test_runner.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import tempfile
2525
import re
2626

27+
TEST_EXIT_PASSED = 0
28+
TEST_EXIT_SKIPPED = 77
29+
2730
BASE_SCRIPTS= [
2831
# Scripts that are run by the travis build process.
2932
# Longest test should go first, to favor running tests in parallel
@@ -245,20 +248,20 @@ def run_tests(test_list, src_dir, build_dir, exeext, jobs=1, enable_coverage=Fal
245248
job_queue = TestHandler(jobs, tests_dir, test_list, flags)
246249

247250
max_len_name = len(max(test_list, key=len))
248-
results = BOLD[1] + "%s | %s | %s\n\n" % ("TEST".ljust(max_len_name), "PASSED", "DURATION") + BOLD[0]
251+
results = BOLD[1] + "%s | %s | %s\n\n" % ("TEST".ljust(max_len_name), "PASSED ", "DURATION") + BOLD[0]
249252
for _ in range(len(test_list)):
250-
(name, stdout, stderr, passed, duration) = job_queue.get_next()
251-
all_passed = all_passed and passed
253+
(name, stdout, stderr, status, duration) = job_queue.get_next()
254+
all_passed = all_passed and status != "Failed"
252255
time_sum += duration
253256

254257
print('\n' + BOLD[1] + name + BOLD[0] + ":")
255-
print('' if passed else stdout + '\n', end='')
258+
print('' if status == "Passed" else stdout + '\n', end='')
256259
print('' if stderr == '' else 'stderr:\n' + stderr + '\n', end='')
257-
print("Pass: %s%s%s, Duration: %s s\n" % (BOLD[1], passed, BOLD[0], duration))
260+
print("Status: %s%s%s, Duration: %s s\n" % (BOLD[1], status, BOLD[0], duration))
258261

259-
results += "%s | %s | %s s\n" % (name.ljust(max_len_name), str(passed).ljust(6), duration)
262+
results += "%s | %s | %s s\n" % (name.ljust(max_len_name), status.ljust(7), duration)
260263

261-
results += BOLD[1] + "\n%s | %s | %s s (accumulated)" % ("ALL".ljust(max_len_name), str(all_passed).ljust(6), time_sum) + BOLD[0]
264+
results += BOLD[1] + "\n%s | %s | %s s (accumulated)" % ("ALL".ljust(max_len_name), str(all_passed).ljust(7), time_sum) + BOLD[0]
262265
print(results)
263266
print("\nRuntime: %s s" % (int(time.time() - time0)))
264267

@@ -315,10 +318,15 @@ def get_next(self):
315318
log_out.seek(0), log_err.seek(0)
316319
[stdout, stderr] = [l.read().decode('utf-8') for l in (log_out, log_err)]
317320
log_out.close(), log_err.close()
318-
passed = stderr == "" and proc.returncode == 0
321+
if proc.returncode == TEST_EXIT_PASSED and stderr == "":
322+
status = "Passed"
323+
elif proc.returncode == TEST_EXIT_SKIPPED:
324+
status = "Skipped"
325+
else:
326+
status = "Failed"
319327
self.num_running -= 1
320328
self.jobs.remove(j)
321-
return name, stdout, stderr, passed, int(time.time() - time0)
329+
return name, stdout, stderr, status, int(time.time() - time0)
322330
print('.', end='', flush=True)
323331

324332

0 commit comments

Comments
 (0)