nixos/test: added verbose output for failed tests

This commit is contained in:
Marijan Petričević 2020-01-14 09:33:10 +01:00
parent 2ac5fab264
commit 61c61f80e5
1 changed files with 13 additions and 5 deletions

View File

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