Merge pull request #79328 from tfc/python-test-driver-reraise
nixosTests: Reraise exceptions in subtests so they stop the test
This commit is contained in:
commit
ae70c38777
@ -85,8 +85,6 @@ CHAR_TO_KEY = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Forward references
|
# Forward references
|
||||||
nr_tests: int
|
|
||||||
failed_tests: list
|
|
||||||
log: "Logger"
|
log: "Logger"
|
||||||
machines: "List[Machine]"
|
machines: "List[Machine]"
|
||||||
|
|
||||||
@ -882,33 +880,16 @@ def run_tests() -> None:
|
|||||||
if machine.is_up():
|
if machine.is_up():
|
||||||
machine.execute("sync")
|
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 len(failed_tests) > 0:
|
|
||||||
eprint(
|
|
||||||
"The following tests have failed:\n - {}".format(
|
|
||||||
"\n - ".join(failed_tests)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def subtest(name: str) -> Iterator[None]:
|
def subtest(name: str) -> Iterator[None]:
|
||||||
global nr_tests
|
|
||||||
global failed_tests
|
|
||||||
|
|
||||||
with log.nested(name):
|
with log.nested(name):
|
||||||
nr_tests += 1
|
|
||||||
try:
|
try:
|
||||||
yield
|
yield
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
failed_tests.append(
|
log.log(f'Test "{name}" failed with error: "{e}"')
|
||||||
'Test "{}" failed with error: "{}"'.format(name, str(e))
|
raise e
|
||||||
)
|
|
||||||
log.log("error: {}".format(str(e)))
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -928,9 +909,6 @@ if __name__ == "__main__":
|
|||||||
]
|
]
|
||||||
exec("\n".join(machine_eval))
|
exec("\n".join(machine_eval))
|
||||||
|
|
||||||
nr_tests = 0
|
|
||||||
failed_tests = []
|
|
||||||
|
|
||||||
@atexit.register
|
@atexit.register
|
||||||
def clean_up() -> None:
|
def clean_up() -> None:
|
||||||
with log.nested("cleaning up"):
|
with log.nested("cleaning up"):
|
||||||
|
Loading…
Reference in New Issue
Block a user