Merge pull request #77662 from marijanp/verbose-python-test-driver

nixos/test: added verbose output for failed tests
This commit is contained in:
Florian Klink 2020-01-17 13:50:49 +01:00 committed by GitHub
commit ed0b5b6133
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -84,7 +84,7 @@ CHAR_TO_KEY = {
# Forward references
nr_tests: int
nr_succeeded: int
failed_tests: list
log: "Logger"
machines: "List[Machine]"
@ -842,23 +842,31 @@ def run_tests() -> None:
machine.execute("sync")
if nr_tests != 0:
nr_succeeded = nr_tests - len(failed_tests)
eprint("{} out of {} tests succeeded".format(nr_succeeded, nr_tests))
if nr_tests > nr_succeeded:
if len(failed_tests) > 0:
eprint(
"The following tests have failed:\n - {}".format(
"\n - ".join(failed_tests)
)
)
sys.exit(1)
@contextmanager
def subtest(name: str) -> Iterator[None]:
global nr_tests
global nr_succeeded
global failed_tests
with log.nested(name):
nr_tests += 1
try:
yield
nr_succeeded += 1
return True
except Exception as e:
failed_tests.append(
'Test "{}" failed with error: "{}"'.format(name, str(e))
)
log.log("error: {}".format(str(e)))
return False
@ -880,7 +888,7 @@ if __name__ == "__main__":
exec("\n".join(machine_eval))
nr_tests = 0
nr_succeeded = 0
failed_tests = []
@atexit.register
def clean_up() -> None: