rpc-tests.py was converted from a shell script into python in #6616 and it shows. There are several idioms which make sense for a shell script, but are considered bad practice in a python module. This PR cleans up some of the quirks.
This pull request combines several commits which improve the code style of rpc-tests.py and move away from bad practices. Reviews/comments for any or all of the commits are welcomed:
- commit 1 replaces the tests_config module and
from tests_config import *
wildcard import with a .ini file and the Python standard library configparser module. Benefits are:- config lives in config files and code lives in source files. Duh.
- avoids a wildcard import, which are usually considered bad practice because it’s difficult to know where names are binded.
- replaces some of the ugly workarounds in #8133 - doesn’t leave a compiled tests_config.pyc file lying around, doesn’t add qa/pull_tester to the python path, allows rpc_tests.py to be run from anywhere.
- commit 2 replaces the roll-your-own argument parsing code with Python3’s standard library argparse module. Benefits are:
- more compact, cleaner code
- passing unknown arguments down to the individual test scripts and selecting which individual test scripts to run is now cleaner
- it should be easier and less bug-prone to add new arguments in future
- commit 3 makes a few miscellaneous improvements to rpc-test.py’s arguments:
- make all arguments start with double dash for consistency. I don’t expect those arguments were being called by automatic tools, so this shouldn’t break any build/test processes.
- improve help text and output
- add nozmq argument to explicitly exclude the ZMQ tests
- commit 4 removes global variables and places logic in main(). Benefits:
- allows rpc-tests.py to be imported and runtests() to be called by external modules.
[EDIT: removed commit hashes since I’ve now rebased]