Skip to content

Commit

Permalink
run_wml_tests: Refactor the output capturing mechanism to use subproc…
Browse files Browse the repository at this point in the history
…ess.PIPE

- Avoids creating tons of external files
- Suppresses the startup banner to reduce extraneous messages
- Makes the system work on Windows
- Fixes an issue of batched tests being misnamed if one of them is an error
  • Loading branch information
CelticMinstrel committed Feb 28, 2021
1 parent ee4ab3f commit 80a77c2
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions run_wml_tests
Expand Up @@ -65,12 +65,6 @@ class TestListParser:
test_list.append(t)
return batcher(test_list)

def get_output_filename(args):
for i,arg in enumerate(args):
if arg == "-u":
return "test-output-"+args[i+1]
raise RuntimeError("No -u option found!")

def run_with_rerun_for_sdl_video(args, timeout):
"""A wrapper for subprocess.run with a workaround for the issue of travis+18.04
intermittently failing to initialise SDL.
Expand All @@ -79,14 +73,10 @@ def run_with_rerun_for_sdl_video(args, timeout):
# be enough.
sdl_retries = 0
while sdl_retries < 10:
# For compatibility with Ubuntu 16.04 LTS, this has to run on Python3.5,
# so the capture_output argument is not available.
filename = get_output_filename(args)
res = subprocess.run(args, timeout=timeout, stdout=open(filename, "w"), stderr=subprocess.STDOUT)
res = subprocess.run(args, timeout=timeout, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
retry = False
with open(filename, "r") as output:
if "Could not initialize SDL_video" in output.read():
retry = True
if b"Could not initialize SDL_video" in res.stdout:
retry = True
if not retry:
return res
sdl_retries += 1
Expand Down Expand Up @@ -115,7 +105,10 @@ class WesnothRunner:
path += "/wesnoth"
if options.debug_bin:
path += "-debug"
self.common_args = [path]
self.common_args = [path, "--nobanner"]
if os.name == 'nt':
self.common_args.append("--wnoconsole")
self.common_args.append("--wnoredirect")
if options.strict_mode:
self.common_args.append("--log-strict=warning")
if options.clean:
Expand Down Expand Up @@ -159,8 +152,10 @@ class WesnothRunner:
except subprocess.TimeoutExpired:
print("Timed out (killed by Python timeout implementation)")
res = subprocess.CompletedProcess(args, UnitTestResult.TIMEOUT.value)
if self.verbose > 1:
print("Result:", res.returncode)
if self.verbose > 0:
print(res.stdout.decode('utf-8'))
if self.verbose > 1:
print("Result:", res.returncode)
if res.returncode < 0:
print("Wesnoth exited because of signal", -res.returncode)
if options.backtrace:
Expand All @@ -171,9 +166,8 @@ class WesnothRunner:
raise UnexpectedTestStatusException()
returned_result = UnitTestResult(res.returncode)
if returned_result != expected_result:
with open(get_output_filename(args), "r") as output:
for line in output.readlines():
print(line)
if self.verbose == 0:
print(res.stdout.decode('utf-8'))
print("Failure, Wesnoth returned", returned_result, "but we expected", expected_result)
raise UnexpectedTestStatusException()

Expand Down

0 comments on commit 80a77c2

Please sign in to comment.