lisa.tests.base.ResultBundle#

class lisa.tests.base.ResultBundle(result, utc_datetime=None, context=None)[source]#

Bases: ResultBundleBase

Bundle for storing test results

Parameters:
  • result (Result) – Indicates whether the associated test passed. It will also be used as the truth-value of a ResultBundle.

  • utc_datetime (datetime.datetime) – UTC time at which the result was collected, or None to record the current datetime.

  • context (dict(str, object)) – Contextual information to attach to the bundle. Keep the content small, as size of ResultBundle instances matters a lot for storing long test sessions results.

TestMetric can be added to an instance of this class. This can make it easier for users of your tests to understand why a certain test passed or failed. For instance:

def test_is_noon():
    now = time.localtime().tm_hour
    res = ResultBundle(Result.PASSED if now == 12 else Result.FAILED)
    res.add_metric("current time", now)

    return res

>>> res_bundle = test_is_noon()
>>> print(res_bundle.result.name)
FAILED

# At this point, the user can wonder why the test failed.
# Metrics are here to help, and are printed along with the result:
>>> print(res_bundle)
FAILED: current time=11

Methods

from_bool()

Alternate constructor where ResultBundle.result is determined from a bool.

raise_skip()

Raise an ResultBundle with the Result.SKIPPED result, thereby short-circuiting the rest of the test.

__bool__() inherited

True if the result is Result.PASSED, False otherwise.

add_metric() inherited

Lets you append several test TestMetric to the bundle.

display_and_exit() inherited

pretty_format() inherited

Methods#

classmethod ResultBundle.from_bool(cond, *args, **kwargs)[source]#

Alternate constructor where ResultBundle.result is determined from a bool

classmethod ResultBundle.raise_skip(msg, from_=None, **kwargs)[source]#

Raise an ResultBundle with the Result.SKIPPED result, thereby short-circuiting the rest of the test.

Parameters:
  • msg (str) – Reason why the test is skipped

  • from (Exception or None) – Other exception that lead to the test being skipped. It will be used as the Y in raise X from Y.

This is typically used as a way to bail out while indicating to the user that the test has essentially been skipped because the target does not support what the test is testing.

ResultBundle.__bool__()#

Inherited method, see lisa.tests.base.ResultBundleBase.__bool__()

True if the result is Result.PASSED, False otherwise.

ResultBundle.add_metric(name, data, units=None)#

Inherited method, see lisa.tests.base.ResultBundleBase.add_metric()

Lets you append several test TestMetric to the bundle.

ResultBundle.display_and_exit() None#

Inherited method, see lisa.tests.base.ResultBundleBase.display_and_exit()

ResultBundle.pretty_format(multiline=True)#

Inherited method, see lisa.tests.base.ResultBundleBase.pretty_format()