aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2017-06-02 11:32:55 +0200
committerMarcoFalke <falke.marco@gmail.com>2017-06-02 11:33:18 +0200
commit1aefc94dd78d6e0c9209cb09fc16f53dedf42108 (patch)
treee70097540c60e9274c4000296f9f799533d1c035 /test/functional/test_framework
parent00d369239612c75548187d4da853bf6878a6f91f (diff)
parent930deb9b2c5a8234d430f0a739c97e1fc961ffad (diff)
Merge #10423: [tests] skipped tests should clean up after themselves
930deb9 [tests] skipped tests should clean up after themselves (John Newbery) Tree-SHA512: ed486c1cf144c223efa738a66e8bb407089a23002871ef5b15c43d4c08641038a20253fc286853b457d66f37a52c81c16f7988aef90635ac262df6ce7bab9b18
Diffstat (limited to 'test/functional/test_framework')
-rwxr-xr-xtest/functional/test_framework/test_framework.py42
1 files changed, 30 insertions, 12 deletions
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index 4b5b311385..45fa5358cb 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -5,6 +5,7 @@
"""Base class for RPC testing."""
from collections import deque
+from enum import Enum
import logging
import optparse
import os
@@ -41,6 +42,15 @@ from .util import (
)
from .authproxy import JSONRPCException
+class TestStatus(Enum):
+ PASSED = 1
+ FAILED = 2
+ SKIPPED = 3
+
+TEST_EXIT_PASSED = 0
+TEST_EXIT_FAILED = 1
+TEST_EXIT_SKIPPED = 77
+
class BitcoinTestFramework(object):
"""Base class for a bitcoin test script.
@@ -57,11 +67,6 @@ class BitcoinTestFramework(object):
This class also contains various public and private helper methods."""
# Methods to override in subclass test scripts.
-
- TEST_EXIT_PASSED = 0
- TEST_EXIT_FAILED = 1
- TEST_EXIT_SKIPPED = 77
-
def __init__(self):
self.num_nodes = 4
self.setup_clean_chain = False
@@ -139,15 +144,18 @@ class BitcoinTestFramework(object):
self.options.tmpdir = tempfile.mkdtemp(prefix="test")
self._start_logging()
- success = False
+ success = TestStatus.FAILED
try:
self.setup_chain()
self.setup_network()
self.run_test()
- success = True
+ success = TestStatus.PASSED
except JSONRPCException as e:
self.log.exception("JSONRPC error")
+ except SkipTest as e:
+ self.log.warning("Test Skipped: %s" % e.message)
+ success = TestStatus.SKIPPED
except AssertionError as e:
self.log.exception("Assertion failed")
except KeyError as e:
@@ -159,11 +167,12 @@ class BitcoinTestFramework(object):
if not self.options.noshutdown:
self.log.info("Stopping nodes")
- self.stop_nodes()
+ if self.nodes:
+ self.stop_nodes()
else:
self.log.info("Note: bitcoinds were not stopped and may still be running")
- if not self.options.nocleanup and not self.options.noshutdown and success:
+ if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED:
self.log.info("Cleaning up")
shutil.rmtree(self.options.tmpdir)
else:
@@ -183,13 +192,17 @@ class BitcoinTestFramework(object):
except OSError:
print("Opening file %s failed." % fn)
traceback.print_exc()
- if success:
+
+ if success == TestStatus.PASSED:
self.log.info("Tests successful")
- sys.exit(self.TEST_EXIT_PASSED)
+ sys.exit(TEST_EXIT_PASSED)
+ elif success == TestStatus.SKIPPED:
+ self.log.info("Test skipped")
+ sys.exit(TEST_EXIT_SKIPPED)
else:
self.log.error("Test failed. Test logging available at %s/test_framework.log", self.options.tmpdir)
logging.shutdown()
- sys.exit(self.TEST_EXIT_FAILED)
+ sys.exit(TEST_EXIT_FAILED)
# Public helper methods. These can be accessed by the subclass test scripts.
@@ -346,6 +359,11 @@ class BitcoinTestFramework(object):
# 2 binaries: 1 test binary, 1 ref binary
# n>2 binaries: 1 test binary, n-1 ref binaries
+class SkipTest(Exception):
+ """This exception is raised to skip a test"""
+ def __init__(self, message):
+ self.message = message
+
class ComparisonTestFramework(BitcoinTestFramework):
def __init__(self):