fix: change to the iOS testing option semantics (#2363)

* Change to the iOS testing option semantics

Don't assume the presence of `python -m` in the test command. Less magic
and allows more option reuse between platforms.

* Update schema

* Add a test for this warning

* Don't try to execute a test-command when it doesn't look like a module

* Update docs/options.md

Co-authored-by: Malcolm Smith <smith@chaquo.com>

* Only allow invalid test command if the first part is 'pytest'

* Responses to code review from @freakboy3742

* Fixes post-merge

---------

Co-authored-by: Malcolm Smith <smith@chaquo.com>
This commit is contained in:
Joe Rickerby
2025-05-18 22:42:23 -04:00
committed by GitHub
co-authored by Malcolm Smith
parent 1bc7e904b8
commit 898f0a45c1
5 changed files with 195 additions and 68 deletions
+39 -2
View File
@@ -32,7 +32,7 @@ from ..util.file import (
download,
move_file,
)
from ..util.helpers import prepare_command
from ..util.helpers import prepare_command, unwrap_preserving_paragraphs
from ..util.packaging import (
combine_constraints,
find_compatible_wheel,
@@ -593,6 +593,43 @@ def build(options: Options, tmp_path: Path) -> None:
)
log.step("Running test suite...")
test_command_parts = shlex.split(build_options.test_command)
if test_command_parts[0:2] != ["python", "-m"]:
first_part = test_command_parts[0]
if first_part == "pytest":
# pytest works exactly the same as a module, so we
# can just run it as a module.
log.warning(
unwrap_preserving_paragraphs(f"""
iOS tests configured with a test command which doesn't start
with 'python -m'. iOS tests must execute python modules - other
entrypoints are not supported.
cibuildwheel will try to execute it as if it started with
'python -m'. If this works, all you need to do is add that to
your test command.
Test command: {build_options.test_command!r}
""")
)
else:
msg = unwrap_preserving_paragraphs(
f"""
iOS tests configured with a test command which doesn't start
with 'python -m'. iOS tests must execute python modules - other
entrypoints are not supported.
Test command: {build_options.test_command!r}
"""
)
raise errors.FatalError(msg)
else:
# the testbed run command actually doesn't want the
# python -m prefix - it's implicit, so we remove it
# here.
test_command_parts = test_command_parts[2:]
try:
call(
"python",
@@ -600,7 +637,7 @@ def build(options: Options, tmp_path: Path) -> None:
"run",
*(["--verbose"] if build_options.build_verbosity > 0 else []),
"--",
*(shlex.split(build_options.test_command)),
*test_command_parts,
env=build_env,
)
failed = False