mobly package

Subpackages

Submodules

mobly.asserts module

mobly.asserts.abort_all(reason, extras=None)[source]

Abort all subsequent tests, including the ones not in this test class or iteration.

Parameters:
  • reason – The reason to abort.
  • extras – An optional field for extra information to be included in test result.
Raises:

signals.TestAbortAll – Abort all subsequent tests.

mobly.asserts.abort_all_if(expr, reason, extras=None)[source]

Abort all subsequent tests, if the expression evaluates to True.

Parameters:
  • expr – The expression that is evaluated.
  • reason – The reason to abort.
  • extras – An optional field for extra information to be included in test result.
Raises:

signals.TestAbortAll – Abort all subsequent tests.

mobly.asserts.abort_class(reason, extras=None)[source]

Abort all subsequent tests within the same test class in one iteration.

If one test class is requested multiple times in a test run, this can only abort one of the requested executions, NOT all.

Parameters:
  • reason – The reason to abort.
  • extras – An optional field for extra information to be included in test result.
Raises:

signals.TestAbortClass – Abort all subsequent tests in a test class.

mobly.asserts.abort_class_if(expr, reason, extras=None)[source]

Abort all subsequent tests within the same test class in one iteration, if expression evaluates to True.

If one test class is requested multiple times in a test run, this can only abort one of the requested executions, NOT all.

Parameters:
  • expr – The expression that is evaluated.
  • reason – The reason to abort.
  • extras – An optional field for extra information to be included in test result.
Raises:

signals.TestAbortClass – Abort all subsequent tests in a test class.

mobly.asserts.assert_almost_equal(first, second, places=None, msg=None, delta=None, extras=None)[source]

Asserts that first is almost equal to second.

Fails if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta. If the two objects compare equal then they automatically compare almost equal.

Parameters:
  • first – The first value to compare.
  • second – The second value to compare.
  • places – How many decimal places to take into account for comparison. Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
  • msg – A string that adds additional info about the failure.
  • delta – Delta to use for comparison instead of decimal places.
  • extras – An optional field for extra information to be included in test result.
mobly.asserts.assert_count_equal(first, second, msg=None, extras=None)[source]

Asserts that two iterables have the same element count.

Element order does not matter. Similar to assert_equal(Counter(list(first)), Counter(list(second))).

Parameters:
  • first – The first iterable to compare.
  • second – The second iterable to compare.
  • msg – A string that adds additional info about the failure.
  • extras – An optional field for extra information to be included in test result.

Example

assert_count_equal([0, 1, 1], [1, 0, 1]) passes the assertion. assert_count_equal([0, 0, 1], [0, 1]) raises an assertion error.

mobly.asserts.assert_equal(first, second, msg=None, extras=None)[source]

Asserts the equality of objects, otherwise fail the test.

Error message is “first != second” by default. Additional explanation can be supplied in the message.

Parameters:
  • first – The first object to compare.
  • second – The second object to compare.
  • msg – A string that adds additional info about the failure.
  • extras – An optional field for extra information to be included in test result.
mobly.asserts.assert_false(expr, msg, extras=None)[source]

Assert an expression evaluates to false, otherwise fail the test.

Parameters:
  • expr – The expression that is evaluated.
  • msg – A string explaining the details in case of failure.
  • extras – An optional field for extra information to be included in test result.
mobly.asserts.assert_greater(a, b, msg=None, extras=None)[source]

Asserts that a > b.

mobly.asserts.assert_greater_equal(a, b, msg=None, extras=None)[source]

Asserts that a >= b.

mobly.asserts.assert_in(member, container, msg=None, extras=None)[source]

Asserts that member is in container.

mobly.asserts.assert_is(expr1, expr2, msg=None, extras=None)[source]

Asserts that expr1 is expr2.

mobly.asserts.assert_is_instance(obj, cls, msg=None, extras=None)[source]

Asserts that obj is an instance of cls.

mobly.asserts.assert_is_none(obj, msg=None, extras=None)[source]

Asserts that obj is None.

mobly.asserts.assert_is_not(expr1, expr2, msg=None, extras=None)[source]

Asserts that expr1 is not expr2.

mobly.asserts.assert_is_not_none(obj, msg=None, extras=None)[source]

Asserts that obj is not None.

mobly.asserts.assert_less(a, b, msg=None, extras=None)[source]

Asserts that a < b.

mobly.asserts.assert_less_equal(a, b, msg=None, extras=None)[source]

Asserts that a <= b.

mobly.asserts.assert_not_almost_equal(first, second, places=None, msg=None, delta=None, extras=None)[source]

Asserts that first is not almost equal to second.

Parameters:
  • first – The first value to compare.
  • second – The second value to compare.
  • places – How many decimal places to take into account for comparison. Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit).
  • msg – A string that adds additional info about the failure.
  • delta – Delta to use for comparison instead of decimal places.
  • extras – An optional field for extra information to be included in test result.
mobly.asserts.assert_not_equal(first, second, msg=None, extras=None)[source]

Asserts that first is not equal (!=) to second.

mobly.asserts.assert_not_in(member, container, msg=None, extras=None)[source]

Asserts that member is not in container.

mobly.asserts.assert_not_is_instance(obj, cls, msg=None, extras=None)[source]

Asserts that obj is not an instance of cls.

mobly.asserts.assert_not_regex(text, unexpected_regex, msg=None, extras=None)[source]

Fails the test if the text matches the regular expression.

mobly.asserts.assert_raises(expected_exception, extras=None, *args, **kwargs)[source]

Assert that an exception is raised when a function is called.

If no exception is raised, test fail. If an exception is raised but not of the expected type, the exception is let through.

This should only be used as a context manager:
with assert_raises(Exception):
func()
Parameters:
  • expected_exception – An exception class that is expected to be raised.
  • extras – An optional field for extra information to be included in test result.
mobly.asserts.assert_raises_regex(expected_exception, expected_regex, extras=None, *args, **kwargs)[source]

Assert that an exception is raised when a function is called.

If no exception is raised, test fail. If an exception is raised but not of the expected type, the exception is let through. If an exception of the expected type is raised but the error message does not match the expected_regex, test fail.

This should only be used as a context manager:
with assert_raises(Exception):
func()
Parameters:
  • expected_exception – An exception class that is expected to be raised.
  • extras – An optional field for extra information to be included in test result.
mobly.asserts.assert_regex(text, expected_regex, msg=None, extras=None)[source]

Fails the test unless the text matches the regular expression.

mobly.asserts.assert_true(expr, msg, extras=None)[source]

Assert an expression evaluates to true, otherwise fail the test.

Parameters:
  • expr – The expression that is evaluated.
  • msg – A string explaining the details in case of failure.
  • extras – An optional field for extra information to be included in test result.
mobly.asserts.explicit_pass(msg, extras=None)[source]

Explicitly pass a test.

This will pass the test explicitly regardless of any other error happened in the test body. E.g. even if errors have been recorded with expects, the test will still be marked pass if this is called.

A test without uncaught exception will pass implicitly so this should be used scarcely.

Parameters:
  • msg – A string explaining the details of the passed test.
  • extras – An optional field for extra information to be included in test result.
Raises:

signals.TestPass – Mark a test as passed.

mobly.asserts.fail(msg, extras=None)[source]

Explicitly fail a test.

Parameters:
  • msg – A string explaining the details of the failure.
  • extras – An optional field for extra information to be included in test result.
Raises:

signals.TestFailure – Mark a test as failed.

mobly.asserts.skip(reason, extras=None)[source]

Skip a test.

Parameters:
  • reason – The reason this test is skipped.
  • extras – An optional field for extra information to be included in test result.
Raises:

signals.TestSkip – Mark a test as skipped.

mobly.asserts.skip_if(expr, reason, extras=None)[source]

Skip a test if expression evaluates to True.

Parameters:
  • expr – The expression that is evaluated.
  • reason – The reason this test is skipped.
  • extras – An optional field for extra information to be included in test result.

mobly.base_instrumentation_test module

mobly.base_test module

mobly.config_parser module

mobly.controller_manager module

mobly.expects module

mobly.keys module

class mobly.keys.Config[source]

Bases: enum.Enum

The reserved keywordss used in configurations.

key_log_path = 'LogPath'
key_mobly_params = 'MoblyParams'
key_testbed = 'TestBeds'
key_testbed_controllers = 'Controllers'
key_testbed_name = 'Name'
key_testbed_test_params = 'TestParams'

mobly.logger module

mobly.records module

mobly.runtime_test_info module

mobly.signals module

This module is where all the test signal classes and related utilities live.

exception mobly.signals.ControllerError[source]

Bases: Exception

Raised when an error occurred in controller classes.

exception mobly.signals.TestAbortAll(details, extras=None)[source]

Bases: mobly.signals.TestAbortSignal

Raised when all subsequent tests should be aborted.

exception mobly.signals.TestAbortClass(details, extras=None)[source]

Bases: mobly.signals.TestAbortSignal

Raised when all subsequent tests within the same test class should be aborted.

exception mobly.signals.TestAbortSignal(details, extras=None)[source]

Bases: mobly.signals.TestSignal

Base class for abort signals.

exception mobly.signals.TestError(details, extras=None)[source]

Bases: mobly.signals.TestSignal

Raised when a test has an unexpected error.

exception mobly.signals.TestFailure(details, extras=None)[source]

Bases: mobly.signals.TestSignal

Raised when a test has failed.

exception mobly.signals.TestPass(details, extras=None)[source]

Bases: mobly.signals.TestSignal

Raised when a test has passed.

exception mobly.signals.TestSignal(details, extras=None)[source]

Bases: Exception

Base class for all test result control signals. This is used to signal the result of a test.

details

A string that describes the reason for raising this signal.

extras

A json-serializable data type to convey extra information about a test result.

exception mobly.signals.TestSignalError[source]

Bases: Exception

Raised when an error occurs inside a test signal.

exception mobly.signals.TestSkip(details, extras=None)[source]

Bases: mobly.signals.TestSignal

Raised when a test has been skipped.

mobly.suite_runner module

mobly.test_runner module

mobly.utils module

Module contents