Skip to content

Commit c8fb268

Browse files
authored
Android test updates (#2575)
* Install the test environment while simulating Android * Pass build-verbosity setting through to the test runner
1 parent 841e718 commit c8fb268

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

cibuildwheel/platforms/android.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ def test_wheel(state: BuildState, wheel: Path) -> None:
589589
site_packages_dir,
590590
f"{wheel}{state.options.test_extras}",
591591
*state.options.test_requires,
592-
env=state.build_env,
592+
env=state.android_env,
593593
)
594594

595595
# Copy test-sources.
@@ -641,6 +641,7 @@ def test_wheel(state: BuildState, wheel: Path) -> None:
641641
site_packages_dir,
642642
"--cwd",
643643
cwd_dir,
644+
*(["-v"] if state.options.build_verbosity > 0 else []),
644645
*test_args,
645646
env=state.build_env,
646647
)

docs/options.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,9 @@ Settings that are not supported for a specific frontend will log a warning.
17241724
The default build frontend is `build`, which does show build backend output by
17251725
default.
17261726

1727+
On Android and iOS, a positive verbosity level will also show more detailed logs from
1728+
the test harness.
1729+
17271730
Platform-specific environment variables are also available:<br/>
17281731
`CIBW_BUILD_VERBOSITY_MACOS` | `CIBW_BUILD_VERBOSITY_WINDOWS` | `CIBW_BUILD_VERBOSITY_LINUX` | `CIBW_BUILD_VERBOSITY_ANDROID` | `CIBW_BUILD_VERBOSITY_IOS` | `CIBW_BUILD_VERBOSITY_PYODIDE`
17291732

test/test_android.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,71 @@ def test_no_test_sources(tmp_path, capfd):
318318
) in capfd.readouterr().err
319319

320320

321+
@needs_emulator
322+
def test_environment_markers(tmp_path):
323+
project = new_c_project()
324+
test_filename = "test_environment_markers.py"
325+
project.files[test_filename] = dedent(
326+
"""\
327+
import pytest
328+
329+
def test_android():
330+
import certifi
331+
332+
def test_not_android():
333+
try:
334+
import platformdirs
335+
except ImportError:
336+
pass
337+
else:
338+
pytest.fail("`platformdirs` should not have been installed")
339+
"""
340+
)
341+
project.generate(tmp_path)
342+
343+
cibuildwheel_run(
344+
tmp_path,
345+
add_env={
346+
**cp313_env,
347+
"CIBW_TEST_COMMAND": f"python -m pytest {test_filename}",
348+
"CIBW_TEST_SOURCES": test_filename,
349+
"CIBW_TEST_REQUIRES": " ".join(
350+
[
351+
"pytest",
352+
"certifi;sys_platform=='android'",
353+
"platformdirs;sys_platform!='android'",
354+
]
355+
),
356+
},
357+
)
358+
359+
360+
@needs_emulator
361+
def test_verbosity(tmp_path, capfd):
362+
new_c_project().generate(tmp_path)
363+
test_env = {
364+
**cp313_env,
365+
"CIBW_TEST_COMMAND": """python -c 'print("Hello world")'""",
366+
}
367+
verbose_lines = [
368+
"> Task :app:packageDebug", # Gradle
369+
"I/TestRunner: run started: 1 tests", # Logcat
370+
]
371+
372+
cibuildwheel_run(tmp_path, add_env=test_env)
373+
stdout = capfd.readouterr().out
374+
for line in verbose_lines:
375+
assert line not in stdout
376+
377+
cibuildwheel_run(
378+
tmp_path,
379+
add_env={**test_env, "CIBW_BUILD_VERBOSITY": "1"},
380+
)
381+
stdout = capfd.readouterr().out
382+
for line in verbose_lines:
383+
assert line in stdout
384+
385+
321386
@needs_emulator
322387
def test_api_level(tmp_path, capfd):
323388
project = new_c_project()

0 commit comments

Comments
 (0)