From 8d41ac9b9b88dee9ef8cf1acd481950221fe8b6d Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Thu, 11 Sep 2025 21:12:24 +0100 Subject: [PATCH] Update Android test-command handling --- cibuildwheel/platforms/android.py | 7 ++++--- test/test_android.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/cibuildwheel/platforms/android.py b/cibuildwheel/platforms/android.py index b3f614fba..2f7e8f7b2 100644 --- a/cibuildwheel/platforms/android.py +++ b/cibuildwheel/platforms/android.py @@ -613,8 +613,8 @@ def test_wheel(state: BuildState, wheel: Path) -> None: # Parse test-command. test_args = shlex.split(test_command) - if test_args[:2] in [["python", "-c"], ["python", "-m"]]: - test_args[:3] = [test_args[1], test_args[2], "--"] + if test_args[0] == "python" and any(arg in test_args for arg in ["-c", "-m"]): + del test_args[0] elif test_args[0] in ["pytest"]: # We transform some commands into the `python -m` form, but this is deprecated. msg = ( @@ -623,7 +623,7 @@ def test_wheel(state: BuildState, wheel: Path) -> None: "If this works, all you need to do is add that to your test command." ) log.warning(msg) - test_args[:1] = ["-m", test_args[0], "--"] + test_args[:1] = ["-m", test_args[0]] else: msg = ( f"Test command {test_command!r} is not supported on Android. " @@ -642,6 +642,7 @@ def test_wheel(state: BuildState, wheel: Path) -> None: "--cwd", cwd_dir, *(["-v"] if state.options.build_verbosity > 0 else []), + "--", *test_args, env=state.build_env, ) diff --git a/test/test_android.py b/test/test_android.py index a391674e8..bd4149ecf 100644 --- a/test/test_android.py +++ b/test/test_android.py @@ -262,6 +262,11 @@ def test_test_command_good(command, expected_output, tmp_path, spam_env, capfd): "Test command './test_spam.py' is not supported on Android. " "Supported commands are 'python -m' and 'python -c'.", ), + ( + "python test_spam.py", + "Test command 'python test_spam.py' is not supported on Android. " + "Supported commands are 'python -m' and 'python -c'.", + ), # Build-time failure: unrecognized placeholder ( "pytest {project}", @@ -283,6 +288,29 @@ def test_test_command_bad(command, expected_output, tmp_path, spam_env, capfd): assert expected_output in capfd.readouterr().err +@needs_emulator +@pytest.mark.parametrize( + ("options", "expected"), + [ + ("", 0), + ("-E", 1), + ], +) +def test_test_command_python_options(options, expected, tmp_path, capfd): + project = new_c_project() + project.generate(tmp_path) + + command = 'import sys; print(f"{sys.flags.ignore_environment=}")' + cibuildwheel_run( + tmp_path, + add_env={ + **cp313_env, + "CIBW_TEST_COMMAND": f"python {options} -c '{command}'", + }, + ) + assert f"sys.flags.ignore_environment={expected}" in capfd.readouterr().out + + @needs_emulator def test_package_subdir(tmp_path, spam_env, capfd): spam_paths = list(tmp_path.iterdir())