Skip to content

Commit f22089c

Browse files
committed
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.
1 parent 1d34f85 commit f22089c

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

cibuildwheel/platforms/ios.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
download,
3333
move_file,
3434
)
35-
from ..util.helpers import prepare_command
35+
from ..util.helpers import prepare_command, unwrap
3636
from ..util.packaging import (
3737
combine_constraints,
3838
find_compatible_wheel,
@@ -593,14 +593,34 @@ def build(options: Options, tmp_path: Path) -> None:
593593
)
594594

595595
log.step("Running test suite...")
596+
597+
test_command_parts = shlex.split(build_options.test_command)
598+
if test_command_parts[0:2] != ["python", "-m"]:
599+
log.warning(
600+
unwrap(f"""
601+
iOS tests run with test command '{build_options.test_command}' that
602+
doesn't start with 'python -m'. iOS tests must execute python
603+
modules - other entrypoints are not supported.
604+
605+
cibuildwheel will try to execute it as if it started with 'python
606+
-m'. If this works, all you need to do is add that to your test
607+
command.
608+
""")
609+
)
610+
else:
611+
# the testbed run command actually doesn't want the
612+
# python -m prefix - it's implicit, so we remove it
613+
# here.
614+
test_command_parts = test_command_parts[2:]
615+
596616
try:
597617
call(
598618
"python",
599619
testbed_path,
600620
"run",
601621
*(["--verbose"] if build_options.build_verbosity > 0 else []),
602622
"--",
603-
*(shlex.split(build_options.test_command)),
623+
*test_command_parts,
604624
env=build_env,
605625
)
606626
failed = False

docs/options.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ run your test suite.
12421242

12431243
On all platforms other than iOS, the command is run in a shell, so you can write things like `cmd1 && cmd2`.
12441244

1245-
On iOS, the value of the `CIBW_TEST_COMMAND` setting is interpreted as the arguments to pass to `python -m` - that is, a Python module name, followed by arguments that will be assigned to `sys.argv`. Shell commands cannot be used.
1245+
On iOS, the value of the `CIBW_TEST_COMMAND` setting should follow the format `python -m MODULE [...ARGS]` - where MODULE is a Python module name, followed by arguments that will be assigned to `sys.argv`. Shell commands cannot be used.
12461246

12471247
Platform-specific environment variables are also available:<br/>
12481248
`CIBW_TEST_COMMAND_MACOS` | `CIBW_TEST_COMMAND_WINDOWS` | `CIBW_TEST_COMMAND_LINUX` | `CIBW_TEST_COMMAND_IOS` | `CIBW_TEST_COMMAND_PYODIDE`
@@ -1262,6 +1262,10 @@ Platform-specific environment variables are also available:<br/>
12621262
CIBW_TEST_COMMAND: >
12631263
pytest ./tests &&
12641264
python ./test.py
1265+
1266+
# run tests on ios
1267+
CIBW_TEST_SOURCES_IOS: tests
1268+
CIBW_TEST_COMMAND_IOS: python -m pytest ./tests
12651269
```
12661270

12671271
!!! tab examples "pyproject.toml"
@@ -1279,6 +1283,11 @@ Platform-specific environment variables are also available:<br/>
12791283
"pytest ./tests",
12801284
"python ./test.py",
12811285
]
1286+
1287+
# run tests on ios
1288+
[tool.cibuildwheel.ios]
1289+
test-sources = ["tests"]
1290+
test-command = "python -m pytest ./tests"
12821291
```
12831292

12841293
In configuration files, you can use an array, and the items will be joined with `&&`.

test/test_ios.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_ios_platforms(tmp_path, build_config, monkeypatch, capfd):
7373
"CIBW_BUILD": "cp313-*",
7474
"CIBW_XBUILD_TOOLS": "does-exist",
7575
"CIBW_TEST_SOURCES": "tests",
76-
"CIBW_TEST_COMMAND": "unittest discover tests test_platform.py",
76+
"CIBW_TEST_COMMAND": "python -m unittest discover tests test_platform.py",
7777
"CIBW_BUILD_VERBOSITY": "1",
7878
**build_config,
7979
},
@@ -119,7 +119,7 @@ def test_no_test_sources(tmp_path, capfd):
119119
add_env={
120120
"CIBW_PLATFORM": "ios",
121121
"CIBW_BUILD": "cp313-*",
122-
"CIBW_TEST_COMMAND": "tests",
122+
"CIBW_TEST_COMMAND": "python -m tests",
123123
},
124124
)
125125

@@ -146,7 +146,7 @@ def test_missing_xbuild_tool(tmp_path, capfd):
146146
add_env={
147147
"CIBW_PLATFORM": "ios",
148148
"CIBW_BUILD": "cp313-*",
149-
"CIBW_TEST_COMMAND": "tests",
149+
"CIBW_TEST_COMMAND": "python -m tests",
150150
"CIBW_XBUILD_TOOLS": "does-not-exist",
151151
},
152152
)

0 commit comments

Comments
 (0)