Files
cibuildwheel/bin/run_tests.py
T

95 lines
2.5 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2022-06-27 19:08:46 +01:00
import argparse
import functools
2019-11-12 23:51:27 +00:00
import os
import subprocess
import sys
2020-06-18 02:00:30 +02:00
from pathlib import Path
2021-05-03 11:45:43 -04:00
if __name__ == "__main__":
if sys.version_info < (3, 13):
default_cpu_count = os.cpu_count() or 2
else:
default_cpu_count = os.process_cpu_count() or 2
make_parser = functools.partial(argparse.ArgumentParser, allow_abbrev=False)
if sys.version_info >= (3, 14):
make_parser = functools.partial(make_parser, color=True, suggest_on_error=True)
parser = make_parser()
2022-06-29 20:18:08 +01:00
parser.add_argument(
"--run-podman", action="store_true", default=False, help="run podman tests (linux only)"
)
2024-02-29 22:27:09 +01:00
parser.add_argument(
"--num-processes",
action="store",
default=default_cpu_count,
help="number of processes to use for testing",
)
2022-06-27 19:08:46 +01:00
args = parser.parse_args()
# move cwd to the project root
2020-06-18 02:00:30 +02:00
os.chdir(Path(__file__).resolve().parents[1])
2017-09-01 13:32:34 +01:00
2022-06-27 19:08:46 +01:00
# unit tests
2021-05-03 11:45:43 -04:00
unit_test_args = [sys.executable, "-m", "pytest", "unit_test"]
2022-06-27 19:08:46 +01:00
if sys.platform.startswith("linux") and os.environ.get("CIBW_PLATFORM", "linux") == "linux":
2022-06-27 19:08:46 +01:00
# run the docker unit tests only on Linux
2021-05-03 11:45:43 -04:00
unit_test_args += ["--run-docker"]
2022-06-29 20:18:08 +01:00
if args.run_podman:
unit_test_args += ["--run-podman"]
2022-06-27 19:08:46 +01:00
print(
"\n\n================================== UNIT TESTS ==================================",
flush=True,
)
2021-02-14 12:56:33 -05:00
subprocess.run(unit_test_args, check=True)
2017-09-01 13:32:34 +01:00
# Run the serial integration tests without multiple processes
serial_integration_test_args = [
sys.executable,
"-m",
"pytest",
"-m",
"serial",
"-x",
"--durations",
"0",
"--timeout=2400",
"test",
"-vv",
]
print(
"\n\n=========================== SERIAL INTEGRATION TESTS ===========================",
flush=True,
)
subprocess.run(serial_integration_test_args, check=True)
# Non-serial integration tests
2022-06-27 19:08:46 +01:00
integration_test_args = [
sys.executable,
"-m",
"pytest",
"-m",
"not serial",
2024-02-29 22:27:09 +01:00
f"--numprocesses={args.num_processes}",
2022-06-27 19:08:46 +01:00
"-x",
"--durations",
"0",
"--timeout=2400",
"test",
"-vv",
2022-06-27 19:08:46 +01:00
]
2022-06-29 20:18:08 +01:00
if sys.platform.startswith("linux") and args.run_podman:
2022-06-27 19:08:46 +01:00
integration_test_args += ["--run-podman"]
print(
"\n\n========================= NON-SERIAL INTEGRATION TESTS =========================",
flush=True,
)
2022-06-27 19:08:46 +01:00
subprocess.run(integration_test_args, check=True)