Install & Compatibility
Where this runs
tested against v1.12.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.378s · 23.3MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.3s · import 0.336s · 25MB
21MB installed
● package 21MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BaseTestClass
✓ from mobly import base_test
test_runner
✓ from mobly import test_runner
AndroidDevice
✓ from mobly.controllers import android_device
snippet_client_v2
✓ from mobly.controllers.android_device_lib import snippet_client_v2
✗ from mobly.controllers.android_device_lib import snippet_client
The old snippet_client was deprecated in v1.12 and removed. Use snippet_client_v2 instead.
callback_event
✓ from mobly.snippet import callback_event
✗ from mobly import snippet_event
The direct import of snippet_event was deprecated in v1.12. Use mobly.snippet.callback_event instead.
callback_handler_v2
✓ from mobly.controllers.android_device_lib import callback_handler_v2
✗ from mobly import callback_handler
The old callback_handler was deprecated in v1.12 and removed. Use callback_handler_v2 instead.
This example demonstrates a basic Mobly test that registers an Android device controller and attempts to display a 'Hello World!' toast message on the device using Mobly Bundled Snippets (MBS). It requires a `sample_config.yml` file to specify the testbed configuration. Ensure 'adb' is configured and 'USB debugging' is enabled on the Android device.
# sample_config.yml
TestBeds:
- Name: SampleTestBed
Controllers:
AndroidDevice: '*'
# hello_world_test.py
from mobly import base_test
from mobly import test_runner
from mobly.controllers import android_device
class HelloWorldTest(base_test.BaseTestClass):
def setup_class(self):
# Registering android_device controller declares the test's dependency on Android devices.
# By default, we expect at least one device is found.
self.ads = self.register_controller(android_device)
self.dut = self.ads[0] # Get the first AndroidDevice object
# Start Mobly Bundled Snippets (MBS) if needed, using the updated MBS_PACKAGE constant
# You may need to install MBS on your device:
# https://github.com/google/mobly-bundled-snippets
try:
self.dut.load_snippet('mbs', android_device.MBS_PACKAGE)
except Exception as e:
self.log.warning(f"Could not load MBS snippet. Make sure it's installed: {e}")
def test_hello(self):
if hasattr(self.dut, 'mbs'):
self.dut.mbs.makeToast('Hello Mobly World!')
else:
self.log.info('MBS not loaded, skipping makeToast. Device detected.')
if __name__ == '__main__':
# To run, save config as sample_config.yml and this file as hello_world_test.py
# Then execute: python hello_world_test.py -c sample_config.yml
test_runner.main()
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mobly.snippet_client'
Using the old, deprecated `snippet_client` import path which was removed after Mobly v1.12.
fixChange the import to `from mobly.controllers.android_device_lib import snippet_client_v2` and update code to use `SnippetClientV2`.
AttributeError: 'AndroidDevice' object has no attribute 'snippet_client'
Attempting to access `ad.snippet_client` on an `AndroidDevice` object after the `snippet_client` module was removed and replaced by `snippet_client_v2`.
fixEnsure you are importing and using `snippet_client_v2` correctly. The common pattern is `self.dut.load_snippet('your_snippet_name', 'com.your.package.name')` which internally uses `snippet_client_v2`. mobly.controllers.android_device.Error: Android device serial "<SERIAL>" is specified in config but is not reachable.
The specified Android device (by serial or wildcard '*') is not detected by `adb devices` or is not in a ready state (e.g., USB debugging disabled, device offline).
fixVerify `adb` is installed and working (`adb devices`), confirm USB debugging is enabled on the device, and ensure the device is properly connected and recognized. Check `adb logcat` for device-side issues.
RuntimeError: Python version must be >= 3.11
Running Mobly with an older Python version than required.
fixUpgrade your Python environment to version 3.11 or newer. You can use `pyenv` or `conda` for managing Python versions.
Upgrade
Version history
1.13latest on PyPI · released May 20, 2025
Audit
Dependencies
pythonrequiredRequires Python 3.11 or newer.
adbrequiredRequired for Android device control. Needs to be installed on the system PATH.