Files
cibuildwheel/bin/run_tests.py
T

127 lines
3.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2022-06-27 19:08:46 +01:00
import argparse
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
parser = argparse.ArgumentParser(allow_abbrev=False)
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",
)
parser.add_argument(
"--test-select",
choices={"all", "native", "android", "ios", "pyodide"},
default="all",
help="Either 'native' or 'android'/'ios'/'pyodide'",
)
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
2025-08-12 09:06:12 -04:00
# doc tests
doc_test_args = [sys.executable, "-m", "pytest", "cibuildwheel"]
print(
"\n\n================================== DOC TESTS ==================================",
flush=True,
)
result = subprocess.run(doc_test_args, check=False)
if result.returncode not in (0, 5):
# Allow case where no doctests are collected (returncode 5) because
# circleci sets an explicit "-k" filter that disables doctests. There
# isn't a pattern that will only select doctests. This can be removed
# and have check=True if the circleci PYTEST_ADDOPTS is removed.
raise subprocess.CalledProcessError(
result.returncode, result.args, output=result.stdout, stderr=result.stderr
)
2022-06-27 19:08:46 +01:00
# unit tests
print(
"\n\n================================== UNIT TESTS ==================================",
flush=True,
)
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"
and args.test_select in ["all", "native"]
):
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
subprocess.run(unit_test_args, check=True)
print(
"\n\n=========================== SERIAL INTEGRATION TESTS ===========================",
flush=True,
)
match args.test_select:
case "all":
marks = []
case "native":
marks = ["not pyodide", "not android", "not ios"]
case mark:
marks = [f"{mark}"]
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",
f"{' and '.join(['serial', *marks])}",
"-x",
"--durations",
"0",
"--timeout=2400",
"test",
"-vv",
]
subprocess.run(serial_integration_test_args, check=True)
print(
"\n\n========================= NON-SERIAL INTEGRATION TESTS =========================",
flush=True,
)
2022-06-27 19:08:46 +01:00
integration_test_args = [
sys.executable,
"-m",
"pytest",
"-m",
f"{' and '.join(['not serial', *marks])}",
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"]
subprocess.run(integration_test_args, check=True)