Skip to content

Commit 36f5d7b

Browse files
committed
Only allow invalid test command if the first part is 'pytest'
1 parent 6658adc commit 36f5d7b

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

cibuildwheel/platforms/ios.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,9 @@ def build(options: Options, tmp_path: Path) -> None:
597597
test_command_parts = shlex.split(build_options.test_command)
598598
if test_command_parts[0:2] != ["python", "-m"]:
599599
first_part = test_command_parts[0]
600-
first_arg_looks_like_a_module_name = all(
601-
n.isidentifier() for n in first_part.split(".")
602-
)
603-
if first_arg_looks_like_a_module_name:
600+
if first_part == "pytest":
601+
# pytest works exactly the same as a module, so we
602+
# can just run it as a module.
604603
log.warning(
605604
unwrap_preserving_paragraphs(f"""
606605
iOS tests configured with a test command which doesn't start
@@ -611,18 +610,17 @@ def build(options: Options, tmp_path: Path) -> None:
611610
'python -m'. If this works, all you need to do is add that to
612611
your test command.
613612
614-
Test command: {build_options.test_command}
613+
Test command: {build_options.test_command!r}
615614
""")
616615
)
617616
else:
618-
# no point in trying to run it as a module - it's not a module
619617
msg = unwrap_preserving_paragraphs(
620618
f"""
621619
iOS tests configured with a test command which doesn't start
622620
with 'python -m'. iOS tests must execute python modules - other
623621
entrypoints are not supported.
624622
625-
Test command: {build_options.test_command}
623+
Test command: {build_options.test_command!r}
626624
"""
627625
)
628626
raise errors.FatalError(msg)

test/test_ios.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,21 @@ def test_empty_xbuild_tool_definition(tmp_path, capfd):
215215

216216

217217
def test_ios_test_command_without_python_dash_m(tmp_path, capfd):
218-
"""Test command should be able to run without python -m."""
218+
"""pytest should be able to run without python -m, but it should warn."""
219219
if utils.platform != "macos":
220220
pytest.skip("this test can only run on macOS")
221221
if utils.get_xcode_version() < (13, 0):
222222
pytest.skip("this test only works with Xcode 13.0 or greater")
223223

224224
project_dir = tmp_path / "project"
225+
225226
project = test_projects.new_c_project()
226-
project.files["tests_module/__init__.py"] = ""
227-
project.files["tests_module/__main__.py"] = textwrap.dedent("""
228-
if __name__ == "__main__":
229-
print("Hello from tests_module")
227+
project.files["tests/__init__.py"] = ""
228+
project.files["tests/test_spam.py"] = textwrap.dedent("""
229+
import spam
230+
def test_spam():
231+
assert spam.filter("spam") == 0
232+
assert spam.filter("ham") != 0
230233
""")
231234
project.generate(project_dir)
232235

@@ -235,8 +238,9 @@ def test_ios_test_command_without_python_dash_m(tmp_path, capfd):
235238
add_env={
236239
"CIBW_PLATFORM": "ios",
237240
"CIBW_BUILD": "cp313-*",
238-
"CIBW_TEST_COMMAND": "tests_module",
239-
"CIBW_TEST_SOURCES": "tests_module",
241+
"CIBW_TEST_COMMAND": "pytest ./tests",
242+
"CIBW_TEST_SOURCES": "tests",
243+
"CIBW_TEST_REQUIRES": "pytest",
240244
"CIBW_XBUILD_TOOLS": "",
241245
},
242246
)

0 commit comments

Comments
 (0)