From c8fb268a1b2323a280eb95dcecb15deae8990911 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Mon, 8 Sep 2025 15:58:43 +0100 Subject: [PATCH] Android test updates (#2575) * Install the test environment while simulating Android * Pass build-verbosity setting through to the test runner --- cibuildwheel/platforms/android.py | 3 +- docs/options.md | 3 ++ test/test_android.py | 65 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/cibuildwheel/platforms/android.py b/cibuildwheel/platforms/android.py index 469f41de..b3f614fb 100644 --- a/cibuildwheel/platforms/android.py +++ b/cibuildwheel/platforms/android.py @@ -589,7 +589,7 @@ def test_wheel(state: BuildState, wheel: Path) -> None: site_packages_dir, f"{wheel}{state.options.test_extras}", *state.options.test_requires, - env=state.build_env, + env=state.android_env, ) # Copy test-sources. @@ -641,6 +641,7 @@ def test_wheel(state: BuildState, wheel: Path) -> None: site_packages_dir, "--cwd", cwd_dir, + *(["-v"] if state.options.build_verbosity > 0 else []), *test_args, env=state.build_env, ) diff --git a/docs/options.md b/docs/options.md index 00c57218..34c082bc 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1724,6 +1724,9 @@ Settings that are not supported for a specific frontend will log a warning. The default build frontend is `build`, which does show build backend output by default. +On Android and iOS, a positive verbosity level will also show more detailed logs from +the test harness. + Platform-specific environment variables are also available:
`CIBW_BUILD_VERBOSITY_MACOS` | `CIBW_BUILD_VERBOSITY_WINDOWS` | `CIBW_BUILD_VERBOSITY_LINUX` | `CIBW_BUILD_VERBOSITY_ANDROID` | `CIBW_BUILD_VERBOSITY_IOS` | `CIBW_BUILD_VERBOSITY_PYODIDE` diff --git a/test/test_android.py b/test/test_android.py index 28f39761..a391674e 100644 --- a/test/test_android.py +++ b/test/test_android.py @@ -318,6 +318,71 @@ def test_no_test_sources(tmp_path, capfd): ) in capfd.readouterr().err +@needs_emulator +def test_environment_markers(tmp_path): + project = new_c_project() + test_filename = "test_environment_markers.py" + project.files[test_filename] = dedent( + """\ + import pytest + + def test_android(): + import certifi + + def test_not_android(): + try: + import platformdirs + except ImportError: + pass + else: + pytest.fail("`platformdirs` should not have been installed") + """ + ) + project.generate(tmp_path) + + cibuildwheel_run( + tmp_path, + add_env={ + **cp313_env, + "CIBW_TEST_COMMAND": f"python -m pytest {test_filename}", + "CIBW_TEST_SOURCES": test_filename, + "CIBW_TEST_REQUIRES": " ".join( + [ + "pytest", + "certifi;sys_platform=='android'", + "platformdirs;sys_platform!='android'", + ] + ), + }, + ) + + +@needs_emulator +def test_verbosity(tmp_path, capfd): + new_c_project().generate(tmp_path) + test_env = { + **cp313_env, + "CIBW_TEST_COMMAND": """python -c 'print("Hello world")'""", + } + verbose_lines = [ + "> Task :app:packageDebug", # Gradle + "I/TestRunner: run started: 1 tests", # Logcat + ] + + cibuildwheel_run(tmp_path, add_env=test_env) + stdout = capfd.readouterr().out + for line in verbose_lines: + assert line not in stdout + + cibuildwheel_run( + tmp_path, + add_env={**test_env, "CIBW_BUILD_VERBOSITY": "1"}, + ) + stdout = capfd.readouterr().out + for line in verbose_lines: + assert line in stdout + + @needs_emulator def test_api_level(tmp_path, capfd): project = new_c_project()