Skip to content

Commit 96bd43c

Browse files
committed
Don't try to execute a test-command when it doesn't look like a module
1 parent a4d3c97 commit 96bd43c

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

cibuildwheel/platforms/ios.py

+29-12
Original file line numberDiff line numberDiff line change
@@ -596,19 +596,36 @@ def build(options: Options, tmp_path: Path) -> None:
596596

597597
test_command_parts = shlex.split(build_options.test_command)
598598
if test_command_parts[0:2] != ["python", "-m"]:
599-
log.warning(
600-
unwrap_preserving_paragraphs(f"""
601-
iOS tests configured with a test command which doesn't start with
602-
'python -m'. iOS tests must execute python modules - other
603-
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-
Test command: {build_options.test_command}
610-
""")
599+
first_part = test_command_parts[0]
600+
first_arg_looks_like_a_module_name = all(
601+
n.isidentifier() for n in first_part.split(".")
611602
)
603+
if first_arg_looks_like_a_module_name:
604+
log.warning(
605+
unwrap_preserving_paragraphs(f"""
606+
iOS tests configured with a test command which doesn't start
607+
with 'python -m'. iOS tests must execute python modules - other
608+
entrypoints are not supported.
609+
610+
cibuildwheel will try to execute it as if it started with
611+
'python -m'. If this works, all you need to do is add that to
612+
your test command.
613+
614+
Test command: {build_options.test_command}
615+
""")
616+
)
617+
else:
618+
# no point in trying to run it as a module - it's not a module
619+
msg = unwrap_preserving_paragraphs(
620+
f"""
621+
iOS tests configured with a test command which doesn't start
622+
with 'python -m'. iOS tests must execute python modules - other
623+
entrypoints are not supported.
624+
625+
Test command: {build_options.test_command}
626+
"""
627+
)
628+
raise errors.FatalError(msg)
612629
else:
613630
# the testbed run command actually doesn't want the
614631
# python -m prefix - it's implicit, so we remove it

test/test_ios.py

+26
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,29 @@ def test_ios_test_command_without_python_dash_m(tmp_path, capfd):
249249
out, err = capfd.readouterr()
250250

251251
assert "iOS tests configured with a test command which doesn't start with 'python -m'" in err
252+
253+
254+
def test_ios_test_command_invalid(tmp_path, capfd):
255+
"""Test command should raise an error if it's clearly invalid."""
256+
if utils.platform != "macos":
257+
pytest.skip("this test can only run on macOS")
258+
if utils.get_xcode_version() < (13, 0):
259+
pytest.skip("this test only works with Xcode 13.0 or greater")
260+
261+
project_dir = tmp_path / "project"
262+
basic_project = test_projects.new_c_project()
263+
basic_project.files["./my_test_script.sh"] = "echo hello"
264+
basic_project.generate(project_dir)
265+
266+
with pytest.raises(subprocess.CalledProcessError):
267+
utils.cibuildwheel_run(
268+
project_dir,
269+
add_env={
270+
"CIBW_PLATFORM": "ios",
271+
"CIBW_TEST_COMMAND": "./my_test_script.sh",
272+
"CIBW_TEST_SOURCES": "./my_test_script.sh",
273+
"CIBW_XBUILD_TOOLS": "",
274+
},
275+
)
276+
out, err = capfd.readouterr()
277+
assert "iOS tests configured with a test command which doesn't start with 'python -m'" in err

0 commit comments

Comments
 (0)