Skip to content

Commit 6803e09

Browse files
committed
Move zmq test skipping logic into individual test case.
This commit uses the new skip test funcationality added in 232b666 to skip the zmq tests if the python zmq module is not available or if bitcoind has been built without zmq support. This removes the zmq-specific logic from test_runner.py. In general it's better if test_runner.py has no knowledge of special cases for individual tests and is a general purpose test runner.
1 parent 987a6c0 commit 6803e09

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

test/functional/test_runner.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
'rawtransactions.py',
7878
'reindex.py',
7979
# vv Tests less than 30s vv
80+
"zmq_test.py",
8081
'mempool_resurrect_test.py',
8182
'txn_doublespend.py --mineblock',
8283
'txn_clone.py',
@@ -110,11 +111,6 @@
110111
'p2p-leaktests.py',
111112
]
112113

113-
ZMQ_SCRIPTS = [
114-
# ZMQ test can only be run if bitcoin was built with zmq-enabled.
115-
# call test_runner.py with -nozmq to explicitly exclude these tests.
116-
'zmq_test.py']
117-
118114
EXTENDED_SCRIPTS = [
119115
# These tests are not run by the travis build process.
120116
# Longest test should go first, to favor running tests in parallel
@@ -149,7 +145,7 @@
149145
]
150146

151147
# Place EXTENDED_SCRIPTS first since it has the 3 longest running tests
152-
ALL_SCRIPTS = EXTENDED_SCRIPTS + BASE_SCRIPTS + ZMQ_SCRIPTS
148+
ALL_SCRIPTS = EXTENDED_SCRIPTS + BASE_SCRIPTS
153149

154150
NON_SCRIPTS = [
155151
# These are python files that live in the functional tests directory, but are not test scripts.
@@ -174,7 +170,6 @@ def main():
174170
parser.add_argument('--jobs', '-j', type=int, default=4, help='how many test scripts to run in parallel. Default=4.')
175171
parser.add_argument('--keepcache', '-k', action='store_true', help='the default behavior is to flush the cache directory on startup. --keepcache retains the cache from the previous testrun.')
176172
parser.add_argument('--quiet', '-q', action='store_true', help='only print results summary and failure logs')
177-
parser.add_argument('--nozmq', action='store_true', help='do not run the zmq tests')
178173
args, unknown_args = parser.parse_known_args()
179174

180175
# Create a set to store arguments and create the passon string
@@ -192,7 +187,6 @@ def main():
192187
enable_wallet = config["components"].getboolean("ENABLE_WALLET")
193188
enable_utils = config["components"].getboolean("ENABLE_UTILS")
194189
enable_bitcoind = config["components"].getboolean("ENABLE_BITCOIND")
195-
enable_zmq = config["components"].getboolean("ENABLE_ZMQ") and not args.nozmq
196190

197191
if config["environment"]["EXEEXT"] == ".exe" and not args.force:
198192
# https://github.com/bitcoin/bitcoin/commit/d52802551752140cf41f0d9a225a43e84404d3e9
@@ -205,27 +199,16 @@ def main():
205199
print("Rerun `configure` with -enable-wallet, -with-utils and -with-daemon and rerun make")
206200
sys.exit(0)
207201

208-
# python3-zmq may not be installed. Handle this gracefully and with some helpful info
209-
if enable_zmq:
210-
try:
211-
import zmq
212-
except ImportError:
213-
print("ERROR: \"import zmq\" failed. Use -nozmq to run without the ZMQ tests."
214-
"To run zmq tests, see dependency info in /test/README.md.")
215-
raise
216-
217202
# Build list of tests
218203
if tests:
219204
# Individual tests have been specified. Run specified tests that exist
220205
# in the ALL_SCRIPTS list. Accept the name with or without .py extension.
221206
test_list = [t for t in ALL_SCRIPTS if
222207
(t in tests or re.sub(".py$", "", t) in tests)]
223208
else:
224-
# No individual tests have been specified. Run base tests, and
225-
# optionally ZMQ tests and extended tests.
209+
# No individual tests have been specified.
210+
# Run all base tests, and optionally run extended tests.
226211
test_list = BASE_SCRIPTS
227-
if enable_zmq:
228-
test_list += ZMQ_SCRIPTS
229212
if args.extended:
230213
# place the EXTENDED_SCRIPTS first since the three longest ones
231214
# are there and the list is shorter

test/functional/zmq_test.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the ZMQ API."""
6+
import configparser
7+
import os
8+
import struct
9+
import sys
610

711
from test_framework.test_framework import BitcoinTestFramework
812
from test_framework.util import *
9-
import zmq
10-
import struct
1113

1214
class ZMQTest (BitcoinTestFramework):
1315

@@ -18,6 +20,21 @@ def __init__(self):
1820
port = 28332
1921

2022
def setup_nodes(self):
23+
# Try to import python3-zmq. Skip this test if the import fails.
24+
try:
25+
import zmq
26+
except ImportError:
27+
self.log.warning("python3-zmq module not available. Skipping zmq tests!")
28+
sys.exit(self.TEST_EXIT_SKIPPED)
29+
30+
# Check that bitcoin has been built with ZMQ enabled
31+
config = configparser.ConfigParser()
32+
config.read_file(open(os.path.dirname(__file__) + "/config.ini"))
33+
34+
if not config["components"].getboolean("ENABLE_ZMQ"):
35+
self.log.warning("bitcoind has not been built with zmq enabled. Skipping zmq tests!")
36+
sys.exit(self.TEST_EXIT_SKIPPED)
37+
2138
self.zmqContext = zmq.Context()
2239
self.zmqSubSocket = self.zmqContext.socket(zmq.SUB)
2340
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock")

0 commit comments

Comments
 (0)