diff --git a/test/functional/feature_help.py b/test/functional/feature_help.py --- a/test/functional/feature_help.py +++ b/test/functional/feature_help.py @@ -3,7 +3,6 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Verify that starting bitcoin with -h works as expected.""" -import subprocess from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal @@ -18,46 +17,48 @@ self.add_nodes(self.num_nodes) # Don't start the node + def get_node_output(self, *, ret_code_expected): + ret_code = self.nodes[0].process.wait(timeout=5) + assert_equal(ret_code, ret_code_expected) + self.nodes[0].stdout.seek(0) + self.nodes[0].stderr.seek(0) + out = self.nodes[0].stdout.read() + err = self.nodes[0].stderr.read() + self.nodes[0].stdout.close() + self.nodes[0].stderr.close() + + # Clean up TestNode state + self.nodes[0].running = False + self.nodes[0].process = None + self.nodes[0].rpc_connected = False + self.nodes[0].rpc = None + + return out, err + def run_test(self): self.log.info("Start bitcoin with -h for help text") - self.nodes[0].start(extra_args=['-h'], - stderr=subprocess.PIPE, stdout=subprocess.PIPE) + self.nodes[0].start(extra_args=['-h']) # Node should exit immediately and output help to stdout. - ret_code = self.nodes[0].process.wait(timeout=1) - assert_equal(ret_code, 0) - output = self.nodes[0].process.stdout.read() + output, _ = self.get_node_output(ret_code_expected=0) assert b'Options' in output self.log.info("Help text received: {} (...)".format(output[0:60])) - self.nodes[0].running = False self.log.info("Start bitcoin with -version for version information") - self.nodes[0].start(extra_args=['-version'], - stderr=subprocess.PIPE, stdout=subprocess.PIPE) + self.nodes[0].start(extra_args=['-version']) # Node should exit immediately and output version to stdout. - ret_code = self.nodes[0].process.wait(timeout=1) - assert_equal(ret_code, 0) - output = self.nodes[0].process.stdout.read() + output, _ = self.get_node_output(ret_code_expected=0) assert b'version' in output self.log.info("Version text received: {} (...)".format(output[0:60])) # Test that arguments not in the help results in an error self.log.info( "Start bitcoind with -fakearg to make sure it does not start") - self.nodes[0].start(extra_args=['-fakearg'], - stderr=subprocess.PIPE, stdout=subprocess.PIPE) + self.nodes[0].start(extra_args=['-fakearg']) # Node should exit immediately and output an error to stderr - ret_code = self.nodes[0].process.wait(timeout=1) - assert_equal(ret_code, 1) - output = self.nodes[0].process.stderr.read() + _, output = self.get_node_output(ret_code_expected=1) assert b'Error parsing command line arguments' in output self.log.info("Error message received: {} (...)".format(output[0:60])) - # Clean up TestNode state - self.nodes[0].running = False - self.nodes[0].process = None - self.nodes[0].rpc_connected = False - self.nodes[0].rpc = None - if __name__ == '__main__': HelpTest().main() diff --git a/test/functional/rpc_users.py b/test/functional/rpc_users.py --- a/test/functional/rpc_users.py +++ b/test/functional/rpc_users.py @@ -4,13 +4,14 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. """Test multiple RPC users.""" +import configparser import http.client import os -import urllib.parse -import subprocess from random import SystemRandom import string -import configparser +import subprocess +import sys +import urllib.parse from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( @@ -37,7 +38,7 @@ config = configparser.ConfigParser() config.read_file(open(self.options.configfile, encoding='utf-8')) gen_rpcauth = config['environment']['RPCAUTH'] - p = subprocess.Popen([gen_rpcauth, self.user], + p = subprocess.Popen([sys.executable, gen_rpcauth, self.user], stdout=subprocess.PIPE, universal_newlines=True) lines = p.stdout.read().splitlines() rpcauth3 = lines[1] diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py --- a/test/functional/test_framework/test_node.py +++ b/test/functional/test_framework/test_node.py @@ -190,8 +190,8 @@ self.default_args = [def_arg for def_arg in self.default_args if rm_arg != def_arg and not def_arg.startswith(rm_arg + '=')] - def start(self, extra_args=None, stdout=None, - stderr=None, *args, **kwargs): + def start(self, extra_args=None, *, stdout=None, + stderr=None, **kwargs): """Start the node.""" if extra_args is None: extra_args = self.extra_args @@ -223,7 +223,6 @@ env=subp_env, stdout=stdout, stderr=stderr, - *args, **kwargs) self.running = True @@ -299,6 +298,9 @@ raise AssertionError( "Unexpected stderr {} != {}".format(stderr, expected_stderr)) + self.stdout.close() + self.stderr.close() + del self.p2ps[:] def is_node_stopped(self):