Host-side Python tests in Fuchsia are executed via fx test, CI, and CQ using
the Fuchsia-vendored Python interpreter (fuchsia-vendored-python).
Defining a Host Test
Use the python_host_test GN template
to define a test target.
Test .py files must use the standard shebang:
#!/usr/bin/env fuchsia-vendored-python
Example BUILD.gn
import("//build/python/python_host_test.gni")
if (is_host) {
python_host_test("my_script_test") {
main_source = "my_script_test.py"
sources = [ "test_helper.py" ]
libraries = [ "//path/to/library:lib" ]
}
}
group("tests") {
testonly = true
public_deps = [ ":my_script_test($host_toolchain)" ]
}
Key GN Parameters
main_source: (Required) Path to the primary.pytest entry point.libraries: (Optional) List ofpython_librarylabels imported by the test.enable_mypy: (Optional) Enables MyPy static type checking. Defaults totrue.
Running Tests
Run tests locally using fx test:
fx test //path/to/my_test:my_script_test