diff --git a/cibuildwheel/platforms/android.py b/cibuildwheel/platforms/android.py index a79c8d0ed..0e2059750 100644 --- a/cibuildwheel/platforms/android.py +++ b/cibuildwheel/platforms/android.py @@ -578,7 +578,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. @@ -630,6 +630,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 48d0eb5d5..b2a978270 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 8b719d433..ccd591dfd 100644 --- a/test/test_android.py +++ b/test/test_android.py @@ -316,6 +316,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()