test: Don't keep journals for skipped tests

Let's make sure we don't save journals for tests that were skipped.
This commit is contained in:
Daan De Meyer
2024-05-07 11:50:11 +02:00
parent 1213fc94b4
commit ca2e19f2b7

View File

@@ -144,24 +144,29 @@ def main():
]
result = subprocess.run(cmd)
# Return code 123 is the expected success code
if result.returncode != 123:
if result.returncode != 77 and journal_file:
cmd = [
'journalctl',
'--no-hostname',
'-o', 'short-monotonic',
'--file', journal_file,
'-u', test_unit,
'-p', 'info',
]
print("Test failed, relevant logs can be viewed with: \n\n"
f"{shlex.join(str(a) for a in cmd)}\n", file=sys.stderr)
exit(result.returncode or 1)
# Do not keep journal files for tests that don't fail.
# Return code 123 is the expected success code
if result.returncode in (123, 77):
# Do not keep journal files for tests that don't fail.
if journal_file:
journal_file.unlink(missing_ok=True)
exit(0 if result.returncode == 123 else 77)
if journal_file:
journal_file.unlink(missing_ok=True)
cmd = [
'journalctl',
'--no-hostname',
'-o', 'short-monotonic',
'--file', journal_file,
'-u', test_unit,
'-p', 'info',
]
print("Test failed, relevant logs can be viewed with: \n\n"
f"{shlex.join(str(a) for a in cmd)}\n", file=sys.stderr)
# 0 also means we failed so translate that to a non-zero exit code to mark the test as failed.
exit(result.returncode or 1)
if __name__ == '__main__':