Skip to content

Commit b4d8549

Browse files
committed
Merge #11858: qa: Prepare tests for Windows
faefd29 qa: Prepare functional tests for Windows (MarcoFalke) Pull request description: * Pass `sys.executable` when calling a python script via the subprocess module * Don't remove the log file while it is still open and written to * Properly use os.pathsep and os.path.sep when modifying the PATH environment variable * util-tests: Use os.path.join for Windows compatibility Ref: #8227 Tree-SHA512: c507a536af104b3bde4366b6634099db826532bd3e7c35d694b5883c550920643b3eab79c76703ca67e1044ed09979e855088f7324321c8d52112514e334d614
2 parents 108af52 + faefd29 commit b4d8549

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def main(self):
9999

100100
PortSeed.n = self.options.port_seed
101101

102-
os.environ['PATH'] = self.options.srcdir + ":" + self.options.srcdir + "/qt:" + os.environ['PATH']
102+
os.environ['PATH'] = self.options.srcdir + os.pathsep + \
103+
self.options.srcdir + os.path.sep + "qt" + os.pathsep + \
104+
os.environ['PATH']
103105

104106
check_json_precision()
105107

@@ -148,10 +150,11 @@ def main(self):
148150
self.log.info("Note: bitcoinds were not stopped and may still be running")
149151

150152
if not self.options.nocleanup and not self.options.noshutdown and success != TestStatus.FAILED:
151-
self.log.info("Cleaning up")
152-
shutil.rmtree(self.options.tmpdir)
153+
self.log.info("Cleaning up {} on exit".format(self.options.tmpdir))
154+
cleanup_tree_on_exit = True
153155
else:
154156
self.log.warning("Not cleaning up dir %s" % self.options.tmpdir)
157+
cleanup_tree_on_exit = False
155158

156159
if success == TestStatus.PASSED:
157160
self.log.info("Tests successful")
@@ -164,6 +167,8 @@ def main(self):
164167
self.log.error("Hint: Call {} '{}' to consolidate all logs".format(os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../combine_logs.py"), self.options.tmpdir))
165168
exit_code = TEST_EXIT_FAILED
166169
logging.shutdown()
170+
if cleanup_tree_on_exit:
171+
shutil.rmtree(self.options.tmpdir)
167172
sys.exit(exit_code)
168173

169174
# Methods to override in subclass test scripts.

test/functional/test_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def main():
268268
if args.help:
269269
# Print help for test_runner.py, then print help of the first script (with args removed) and exit.
270270
parser.print_help()
271-
subprocess.check_call([(config["environment"]["SRCDIR"] + '/test/functional/' + test_list[0].split()[0])] + ['-h'])
271+
subprocess.check_call([sys.executable, os.path.join(config["environment"]["SRCDIR"], 'test', 'functional', test_list[0].split()[0]), '-h'])
272272
sys.exit(0)
273273

274274
check_script_list(config["environment"]["SRCDIR"])
@@ -312,7 +312,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
312312
if len(test_list) > 1 and jobs > 1:
313313
# Populate cache
314314
try:
315-
subprocess.check_output([tests_dir + 'create_cache.py'] + flags + ["--tmpdir=%s/cache" % tmpdir])
315+
subprocess.check_output([sys.executable, tests_dir + 'create_cache.py'] + flags + ["--tmpdir=%s/cache" % tmpdir])
316316
except subprocess.CalledProcessError as e:
317317
sys.stdout.buffer.write(e.output)
318318
raise
@@ -342,7 +342,7 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
342342
print('\n============')
343343
print('{}Combined log for {}:{}'.format(BOLD[1], testdir, BOLD[0]))
344344
print('============\n')
345-
combined_logs, _ = subprocess.Popen([os.path.join(tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate()
345+
combined_logs, _ = subprocess.Popen([sys.executble, os.path.join(tests_dir, 'combine_logs.py'), '-c', testdir], universal_newlines=True, stdout=subprocess.PIPE).communicate()
346346
print("\n".join(deque(combined_logs.splitlines(), combined_logs_len)))
347347

348348
print_results(test_results, max_len_name, (int(time.time() - time0)))
@@ -412,7 +412,7 @@ def get_next(self):
412412
tmpdir_arg = ["--tmpdir={}".format(testdir)]
413413
self.jobs.append((t,
414414
time.time(),
415-
subprocess.Popen([self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg,
415+
subprocess.Popen([sys.executable, self.tests_dir + test_argv[0]] + test_argv[1:] + self.flags + portseed_arg + tmpdir_arg,
416416
universal_newlines=True,
417417
stdout=log_stdout,
418418
stderr=log_stderr),

test/util/bitcoin-util-test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def main():
4444
# Add the format/level to the logger
4545
logging.basicConfig(format=formatter, level=level)
4646

47-
bctester(os.path.join(env_conf["SRCDIR"], "test/util/data"), "bitcoin-util-test.json", env_conf)
47+
bctester(os.path.join(env_conf["SRCDIR"], "test", "util", "data"), "bitcoin-util-test.json", env_conf)
4848

4949
def bctester(testDir, input_basename, buildenv):
5050
""" Loads and parses the input file, runs all tests and reports results"""

0 commit comments

Comments
 (0)