Allow -x in hardware tests to fail fast

This commit is contained in:
Joe Knapper 2026-05-13 17:49:38 +01:00 committed by jaknapper
parent 182c67e105
commit 62aa377956

View file

@ -50,9 +50,16 @@ def _get_hashes(include_coverage: bool = False) -> dict[str, str]:
return hashes return hashes
def run_tests() -> None: def run_tests(exitfirst: bool = False) -> None:
"""Run the picamera tests, zip the coverage database, hash relevant source files.""" """Run the picamera tests, zip the coverage database, hash relevant source files."""
subprocess.run(["pytest", "tests/hardware_specific_tests"], check=True) pytest_cmd = ["pytest"]
if exitfirst:
pytest_cmd.append("-x")
pytest_cmd.append("tests/hardware_specific_tests")
subprocess.run(pytest_cmd, check=True)
shutil.copyfile(".coverage", COVERAGE_FILE) shutil.copyfile(".coverage", COVERAGE_FILE)
hash_dict = _get_hashes(include_coverage=True) hash_dict = _get_hashes(include_coverage=True)
with open(HASH_FILE, "w", encoding="utf-8") as json_file: with open(HASH_FILE, "w", encoding="utf-8") as json_file:
@ -103,16 +110,22 @@ def main() -> None:
) )
subparsers = parser.add_subparsers(dest="command", required=True) subparsers = parser.add_subparsers(dest="command", required=True)
subparsers.add_parser("run", help="Run hardware-specific tests on the PiCamera") run_parser = subparsers.add_parser(
"run",
help="Run hardware-specific tests on the PiCamera",
)
subparsers.add_parser( run_parser.add_argument(
"unzip", help="Unzip and verify coverage data on another machine" "-x",
"--exitfirst",
action="store_true",
help="Stop on first test failure",
) )
args = parser.parse_args() args = parser.parse_args()
if args.command == "run": if args.command == "run":
run_tests() run_tests(exitfirst=args.exitfirst)
elif args.command == "unzip": elif args.command == "unzip":
unzip_coverage() unzip_coverage()