Registry / testing / mobly
library1.13pypypi✓ verified 85d ago

Mobly is an open-source, Python-based test framework for host-driven, end-to-end automated testing, specializing in scenarios requiring multiple devices, complex environments, or custom hardware setups. It is currently at version 1.13 and has a regular release cadence, with recent releases focusing on improvements, bug fixes, and Python 3.11+ compatibility.

pip install mobly
INSTALL
IMPORT
SIG · MOBLY
M
mobly
testingpythonv1.13
Install
3.3s avg
Import
357ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.378s · 23.3MB
glibc
py 3.103.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()
Debug
Known issues
breakingPython 2 support was completely removed in Mobly v1.11. All legacy Python 2 specific workarounds and APIs are no longer available.
fix
Migrate all test code to Python 3. Mobly now requires Python 3.11 or newer.
affects: >=1.11
breakingThe minimum required Python version for Mobly was bumped to 3.11 in v1.12.3.
fix
Upgrade your Python environment to 3.11 or later.
affects: >=1.12.3
deprecatedThe old Android snippet client (`snippet_client`), `snippet_event`, and `callback_handler` were deprecated in v1.12 and subsequently removed. The new generic Mobly snippet base client and Android snippet client (`snippet_client_v2`, `callback_handler_v2`) are now in use.
fix
Update imports and code: `snippet_client` -> `snippet_client_v2`, `snippet_event` -> `mobly.snippet.callback_event`, `callback_handler` -> `callback_handler_v2`.
affects: >=1.12
deprecatedThe `get_available_host_port` function was deprecated in v1.12.3.
fix
Rely on the operating system to allocate ports instead of using this function.
affects: >=1.12.3
breakingAll SL4A (Scripting Layer for Android) related code was removed in Mobly v1.13.
fix
Refactor tests to use Mobly Snippet Lib or other modern Android interaction methods instead of SL4A.
affects: >=1.13
gotchaErrors raised from `teardown_class` methods do not trigger the `on_fail` callback.
fix
Handle exceptions within `teardown_class` explicitly if specific failure logic is required, or ensure `on_fail` logic is sufficient for other test stages.
affects: All
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.
fix
Change 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`.
fix
Ensure 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).
fix
Verify `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.
fix
Upgrade 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.
Agent activity
12 hits · last 30 days
node
10
Resources
mobly — pip install mobly · libregistry