@@ -105,6 +105,34 @@ def __init__(self):
105
105
def main (self ):
106
106
"""Main function. This should not be overridden by the subclass test scripts."""
107
107
108
+ self .parse_args ()
109
+
110
+ try :
111
+ self .setup ()
112
+ self .run_test ()
113
+ except JSONRPCException :
114
+ self .log .exception ("JSONRPC error" )
115
+ self .success = TestStatus .FAILED
116
+ except SkipTest as e :
117
+ self .log .warning ("Test Skipped: %s" % e .message )
118
+ self .success = TestStatus .SKIPPED
119
+ except AssertionError :
120
+ self .log .exception ("Assertion failed" )
121
+ self .success = TestStatus .FAILED
122
+ except KeyError :
123
+ self .log .exception ("Key error" )
124
+ self .success = TestStatus .FAILED
125
+ except Exception :
126
+ self .log .exception ("Unexpected exception caught during testing" )
127
+ self .success = TestStatus .FAILED
128
+ except KeyboardInterrupt :
129
+ self .log .warning ("Exiting after keyboard interrupt" )
130
+ self .success = TestStatus .FAILED
131
+ finally :
132
+ exit_code = self .shutdown ()
133
+ sys .exit (exit_code )
134
+
135
+ def parse_args (self ):
108
136
parser = argparse .ArgumentParser (usage = "%(prog)s [options]" )
109
137
parser .add_argument ("--nocleanup" , dest = "nocleanup" , default = False , action = "store_true" ,
110
138
help = "Leave bitcoinds and test.* datadir on exit or error" )
@@ -135,6 +163,9 @@ def main(self):
135
163
self .add_options (parser )
136
164
self .options = parser .parse_args ()
137
165
166
+ def setup (self ):
167
+ """Call this method to start up the test framework object with options set."""
168
+
138
169
PortSeed .n = self .options .port_seed
139
170
140
171
check_json_precision ()
@@ -181,33 +212,20 @@ def main(self):
181
212
self .network_thread = NetworkThread ()
182
213
self .network_thread .start ()
183
214
184
- success = TestStatus .FAILED
215
+ if self .options .usecli :
216
+ if not self .supports_cli :
217
+ raise SkipTest ("--usecli specified but test does not support using CLI" )
218
+ self .skip_if_no_cli ()
219
+ self .skip_test_if_missing_module ()
220
+ self .setup_chain ()
221
+ self .setup_network ()
185
222
186
- try :
187
- if self .options .usecli :
188
- if not self .supports_cli :
189
- raise SkipTest ("--usecli specified but test does not support using CLI" )
190
- self .skip_if_no_cli ()
191
- self .skip_test_if_missing_module ()
192
- self .setup_chain ()
193
- self .setup_network ()
194
- self .run_test ()
195
- success = TestStatus .PASSED
196
- except JSONRPCException :
197
- self .log .exception ("JSONRPC error" )
198
- except SkipTest as e :
199
- self .log .warning ("Test Skipped: %s" % e .message )
200
- success = TestStatus .SKIPPED
201
- except AssertionError :
202
- self .log .exception ("Assertion failed" )
203
- except KeyError :
204
- self .log .exception ("Key error" )
205
- except Exception :
206
- self .log .exception ("Unexpected exception caught during testing" )
207
- except KeyboardInterrupt :
208
- self .log .warning ("Exiting after keyboard interrupt" )
223
+ self .success = TestStatus .PASSED
224
+
225
+ def shutdown (self ):
226
+ """Call this method to shut down the test framework object."""
209
227
210
- if success == TestStatus .FAILED and self .options .pdbonfailure :
228
+ if self . success == TestStatus .FAILED and self .options .pdbonfailure :
211
229
print ("Testcase failed. Attaching python debugger. Enter ? for help" )
212
230
pdb .set_trace ()
213
231
@@ -225,7 +243,7 @@ def main(self):
225
243
should_clean_up = (
226
244
not self .options .nocleanup and
227
245
not self .options .noshutdown and
228
- success != TestStatus .FAILED and
246
+ self . success != TestStatus .FAILED and
229
247
not self .options .perf
230
248
)
231
249
if should_clean_up :
@@ -238,10 +256,10 @@ def main(self):
238
256
self .log .warning ("Not cleaning up dir {}" .format (self .options .tmpdir ))
239
257
cleanup_tree_on_exit = False
240
258
241
- if success == TestStatus .PASSED :
259
+ if self . success == TestStatus .PASSED :
242
260
self .log .info ("Tests successful" )
243
261
exit_code = TEST_EXIT_PASSED
244
- elif success == TestStatus .SKIPPED :
262
+ elif self . success == TestStatus .SKIPPED :
245
263
self .log .info ("Test skipped" )
246
264
exit_code = TEST_EXIT_SKIPPED
247
265
else :
@@ -251,7 +269,7 @@ def main(self):
251
269
logging .shutdown ()
252
270
if cleanup_tree_on_exit :
253
271
shutil .rmtree (self .options .tmpdir )
254
- sys . exit ( exit_code )
272
+ return exit_code
255
273
256
274
# Methods to override in subclass test scripts.
257
275
def set_test_params (self ):
0 commit comments