Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixosTests: Reraise exceptions in subtests so they stop the test #79328

Merged
merged 2 commits into from Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 2 additions & 24 deletions nixos/lib/test-driver/test-driver.py
Expand Up @@ -85,8 +85,6 @@
}

# Forward references
nr_tests: int
failed_tests: list
log: "Logger"
machines: "List[Machine]"

Expand Down Expand Up @@ -882,33 +880,16 @@ def run_tests() -> None:
if machine.is_up():
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
def subtest(name: str) -> Iterator[None]:
global nr_tests
global failed_tests

with log.nested(name):
nr_tests += 1
try:
yield
return True
except Exception as e:
failed_tests.append(
'Test "{}" failed with error: "{}"'.format(name, str(e))
)
log.log("error: {}".format(str(e)))
log.log(f'Test "{name}" failed with error: "{e}"')
raise e

return False

Expand All @@ -928,9 +909,6 @@ def subtest(name: str) -> Iterator[None]:
]
exec("\n".join(machine_eval))

nr_tests = 0
failed_tests = []

@atexit.register
def clean_up() -> None:
with log.nested("cleaning up"):
Expand Down