Skip to content

Commit

Permalink
Some adjustments to runtest.py
Browse files Browse the repository at this point in the history
* Close a hole where if logging (-o) *and* multi-job (-j),
  the feedback from the tests was not logged. (-j)
* Clear list of failed tests if no tests failed.
* add a flush method to the Tee class, there are error conditions
  where the lack of a flush threw an exception.

Signed-off-by: Mats Wichmann <mats@linux.com>
  • Loading branch information
mwichmann committed Nov 10, 2021
1 parent fc2facd commit b89ae15
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
performs test discovery and processes tests according to options.
"""

# TODO: normalize requested and testlist/exclude paths for easier comparison.
# e.g.: "runtest foo/bar" on windows will produce paths like foo/bar\test.py
# this is hard to match with excludelists, and makes those both os.sep-specific
# and command-line-typing specific.

import argparse
import glob
import os
Expand Down Expand Up @@ -190,9 +195,10 @@
)
sys.exit(1)

if args.jobs > 1:
# don't let tests write stdout/stderr directly if multi-job,
# else outputs will interleave and be hard to read
if args.jobs > 1 or args.output:
# 1. don't let tests write stdout/stderr directly if multi-job,
# else outputs will interleave and be hard to read.
# 2. If we're going to write a logfile, we also need to catch the output.
catch_output = True

if not args.printcommand:
Expand Down Expand Up @@ -231,14 +237,23 @@ def __getattr__(self, attr):
# print = functools.partial(print, flush)

if args.output:
logfile = open(args.output, 'w')
class Tee:
def __init__(self, openfile, stream):
self.file = openfile
self.stream = stream

def write(self, data):
self.file.write(data)
self.stream.write(data)

def flush(self, data):
self.file.flush(data)
self.stream.flush(data)

logfile = open(args.output, 'w')
# this is not ideal: we monkeypatch stdout/stderr a second time
# (already did for Unbuffered), so here we can't easily detect what
# state we're in on closedown. Just hope it's okay...
sys.stdout = Tee(logfile, sys.stdout)
sys.stderr = Tee(logfile, sys.stderr)

Expand Down Expand Up @@ -831,12 +846,13 @@ def run(self):
sys.stdout.write("\t" + "\n\t".join(paths) + "\n")

# save the fails to a file
if fail and args.error_log:
paths = [x.path for x in fail]
#print(f"DEBUG: Writing fails to {args.error_log}")
if args.error_log:
with open(args.error_log, "w") as f:
for test in paths:
print(test, file=f)
if fail:
paths = [x.path for x in fail]
for test in paths:
print(test, file=f)
# if there are no fails, file will be cleared

if args.xml:
if args.output == '-':
Expand Down

0 comments on commit b89ae15

Please sign in to comment.