Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | def main(self): | ||||
"--usecli specified but test does not support using CLI") | "--usecli specified but test does not support using CLI") | ||||
self.setup_chain() | self.setup_chain() | ||||
self.setup_network() | self.setup_network() | ||||
self.run_test() | self.run_test() | ||||
success = TestStatus.PASSED | success = TestStatus.PASSED | ||||
except JSONRPCException as e: | except JSONRPCException as e: | ||||
self.log.exception("JSONRPC error") | self.log.exception("JSONRPC error") | ||||
except SkipTest as e: | except SkipTest as e: | ||||
self.log.warning("Test Skipped: %s" % e.message) | self.log.warning("Test Skipped: {}".format(e.message)) | ||||
success = TestStatus.SKIPPED | success = TestStatus.SKIPPED | ||||
except AssertionError as e: | except AssertionError as e: | ||||
self.log.exception("Assertion failed") | self.log.exception("Assertion failed") | ||||
except KeyError as e: | except KeyError as e: | ||||
self.log.exception("Key error") | self.log.exception("Key error") | ||||
except Exception as e: | except Exception as e: | ||||
self.log.exception("Unexpected exception caught during testing") | self.log.exception("Unexpected exception caught during testing") | ||||
except KeyboardInterrupt as e: | except KeyboardInterrupt as e: | ||||
Show All 10 Lines | def main(self): | ||||
else: | else: | ||||
self.log.info( | self.log.info( | ||||
"Note: bitcoinds were not stopped and may still be running") | "Note: bitcoinds were not stopped and may still be running") | ||||
if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED: | if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED: | ||||
self.log.info("Cleaning up") | self.log.info("Cleaning up") | ||||
shutil.rmtree(self.options.tmpdir) | shutil.rmtree(self.options.tmpdir) | ||||
else: | else: | ||||
self.log.warning("Not cleaning up dir %s" % self.options.tmpdir) | self.log.warning( | ||||
"Not cleaning up dir {}".format(self.options.tmpdir)) | |||||
if os.getenv("PYTHON_DEBUG", ""): | if os.getenv("PYTHON_DEBUG", ""): | ||||
# Dump the end of the debug logs, to aid in debugging rare | # Dump the end of the debug logs, to aid in debugging rare | ||||
# travis failures. | # travis failures. | ||||
import glob | import glob | ||||
filenames = [self.options.tmpdir + "/test_framework.log"] | filenames = [self.options.tmpdir + "/test_framework.log"] | ||||
filenames += glob.glob(self.options.tmpdir + | filenames += glob.glob(self.options.tmpdir + | ||||
"/node*/regtest/debug.log") | "/node*/regtest/debug.log") | ||||
MAX_LINES_TO_PRINT = 1000 | MAX_LINES_TO_PRINT = 1000 | ||||
for fn in filenames: | for fn in filenames: | ||||
try: | try: | ||||
with open(fn, 'r') as f: | with open(fn, 'r') as f: | ||||
print("From", fn, ":") | print("From", fn, ":") | ||||
print("".join(deque(f, MAX_LINES_TO_PRINT))) | print("".join(deque(f, MAX_LINES_TO_PRINT))) | ||||
except OSError: | except OSError: | ||||
print("Opening file %s failed." % fn) | print("Opening file {} failed.".format(fn)) | ||||
traceback.print_exc() | traceback.print_exc() | ||||
if success == TestStatus.PASSED: | if success == TestStatus.PASSED: | ||||
self.log.info("Tests successful") | self.log.info("Tests successful") | ||||
sys.exit(TEST_EXIT_PASSED) | sys.exit(TEST_EXIT_PASSED) | ||||
elif success == TestStatus.SKIPPED: | elif success == TestStatus.SKIPPED: | ||||
self.log.info("Test skipped") | self.log.info("Test skipped") | ||||
sys.exit(TEST_EXIT_SKIPPED) | sys.exit(TEST_EXIT_SKIPPED) | ||||
else: | else: | ||||
self.log.error( | self.log.error( | ||||
"Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir) | "Test failed. Test logging available at {}/test_framework.log".format(self.options.tmpdir)) | ||||
logging.shutdown() | logging.shutdown() | ||||
sys.exit(TEST_EXIT_FAILED) | sys.exit(TEST_EXIT_FAILED) | ||||
# Methods to override in subclass test scripts. | # Methods to override in subclass test scripts. | ||||
def set_test_params(self): | def set_test_params(self): | ||||
"""Tests must this method to change default values for number of nodes, topology, etc""" | """Tests must this method to change default values for number of nodes, topology, etc""" | ||||
raise NotImplementedError | raise NotImplementedError | ||||
▲ Show 20 Lines • Show All 319 Lines • Show Last 20 Lines |