diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -172,11 +172,13 @@ def main(): # Read config generated by configure. config = configparser.ConfigParser() - configfile = os.path.abspath(os.path.dirname(__file__)) + "/../config.ini" + configfile = os.path.join(os.path.abspath( + os.path.dirname(__file__)), "..", "config.ini") config.read_file(open(configfile)) src_dir = config["environment"]["SRCDIR"] - tests_dir = src_dir + '/test/functional/' + build_dir = config["environment"]["BUILDDIR"] + tests_dir = os.path.join(src_dir, 'test', 'functional') # Parse arguments and pass through unrecognised args parser = argparse.ArgumentParser(add_help=False, @@ -204,7 +206,8 @@ parser.add_argument('--tmpdirprefix', '-t', default=tempfile.gettempdir(), help="Root directory for datadirs") parser.add_argument('--junitouput', '-ju', - default=tests_dir + 'junit_results.xml', help="file that will store JUnit formated test results ") + default=os.path.join(build_dir, 'junit_results.xml'), help="file that will store JUnit formated test results.") + args, unknown_args = parser.parse_known_args() # Create a set to store arguments and create the passon string @@ -217,7 +220,7 @@ logging.basicConfig(format='%(message)s', level=logging_level) # Create base test directory - tmpdir = "%s/bitcoin_test_runner_%s" % ( + tmpdir = os.path.join("%s", "bitcoin_test_runner_%s") % ( args.tmpdirprefix, datetime.datetime.now().strftime("%Y%m%d_%H%M%S")) os.makedirs(tmpdir) @@ -274,16 +277,16 @@ # and exit. parser.print_help() subprocess.check_call( - (tests_dir + test_list[0]).split() + ['-h']) + [os.path.join(tests_dir, test_list[0]), '-h']) sys.exit(0) check_script_list(src_dir) if not args.keepcache: - shutil.rmtree("%s/test/cache" % - config["environment"]["BUILDDIR"], ignore_errors=True) + shutil.rmtree(os.path.join(build_dir, "test", + "cache"), ignore_errors=True) - run_tests(test_list, src_dir, config["environment"]["BUILDDIR"], tests_dir, args.junitouput, + run_tests(test_list, src_dir, build_dir, tests_dir, args.junitouput, config["environment"]["EXEEXT"], tmpdir, args.jobs, args.coverage, passon_args) @@ -298,17 +301,19 @@ pass # Warn if there is a cache directory - cache_dir = "%s/test/cache" % build_dir + cache_dir = os.path.join(build_dir, "test", "cache") if os.path.isdir(cache_dir): print("%sWARNING!%s There is a cache directory here: %s. If tests fail unexpectedly, try deleting the cache directory." % ( BOLD[1], BOLD[0], cache_dir)) # Set env vars if "BITCOIND" not in os.environ: - os.environ["BITCOIND"] = build_dir + '/src/bitcoind' + exeext - os.environ["BITCOINCLI"] = build_dir + '/src/bitcoin-cli' + exeext + os.environ["BITCOIND"] = os.path.join( + build_dir, 'src', 'bitcoind' + exeext) + os.environ["BITCOINCLI"] = os.path.join( + build_dir, 'src', 'bitcoin-cli' + exeext) - flags = ["--srcdir={}/src".format(build_dir)] + args + flags = [os.path.join("--srcdir={}".format(build_dir), "src")] + args flags.append("--cachedir=%s" % cache_dir) if enable_coverage: @@ -321,7 +326,7 @@ if len(test_list) > 1 and jobs > 1: # Populate cache subprocess.check_output( - [tests_dir + 'create_cache.py'] + flags + ["--tmpdir=%s/cache" % tmpdir]) + [os.path.join(tests_dir, 'create_cache.py')] + flags + [os.path.join("--tmpdir=%s", "cache") % tmpdir]) # Run Tests job_queue = TestHandler(jobs, tests_dir, tmpdir, test_list, flags) @@ -417,11 +422,11 @@ log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16) log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16) test_argv = t.split() - tmpdir = ["--tmpdir=%s/%s_%s" % - (self.tmpdir, re.sub(".py$", "", test_argv[0]), portseed)] + tmpdir = [os.path.join("--tmpdir=%s", "%s_%s") % + (self.tmpdir, re.sub(".py$", "", t), portseed)] self.jobs.append((t, time.time(), - subprocess.Popen([self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir, + subprocess.Popen([os.path.join(self.tests_dir, test_argv[0])] + test_argv[1:] + self.flags + portseed_arg + tmpdir, universal_newlines=True, stdout=log_stdout, stderr=log_stderr), @@ -484,7 +489,7 @@ Check that there are no scripts in the functional tests directory which are not being run by pull-tester.py.""" - script_dir = src_dir + '/test/functional/' + script_dir = os.path.join(src_dir, 'test', 'functional') python_files = set([t for t in os.listdir(script_dir) if t[-3:] == ".py"]) missed_tests = list( python_files - set(map(lambda x: x.split()[0], ALL_SCRIPTS + NON_SCRIPTS)))