Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cd31173 authored by Jack He's avatar Jack He
Browse files

Cert: Add test to verify exception chaining with test decorators

Bug: 154039076
Test: gd/cert/run --host --test_filter=CertSelfTest
Change-Id: Ide19f873d8814cda69d5231eb1bfc41c77bd8722
parent a760c7fa
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
from datetime import datetime, timedelta
import logging
import time
import traceback

from mobly import asserts

@@ -528,6 +529,31 @@ class CertSelfTest(BaseTestClass):
        else:
            asserts.fail("Must throw an exception using @metadata decorator")

    def test_metadata_test_with_exception_stacktrace(self):

        @metadata(pts_test_id="A/B/C", pts_test_name="Hello world")
        def simple_fail_test(failure_argument):
            raise ValueError(failure_argument)

        try:
            simple_fail_test("BEEFBEEF")
        except signals.TestError as e:
            asserts.assert_true(
                "pts_test_id" in e.extras,
                msg=("pts_test_id not in extra: %s" % str(e.extras)))
            asserts.assert_equal(e.extras["pts_test_id"], "A/B/C")
            asserts.assert_true(
                "pts_test_name" in e.extras,
                msg=("pts_test_name not in extra: %s" % str(e.extras)))
            asserts.assert_equal(e.extras["pts_test_name"], "Hello world")
            trace_str = traceback.format_exc()
            asserts.assert_true(
                "raise ValueError(failure_argument)" in trace_str,
                msg="Failed test method not in error stack trace: %s" %
                trace_str)
        else:
            asserts.fail("Must throw an exception using @metadata decorator")

    def test_fluent_behavior_simple(self):
        thing = ObjectWithBehaviors()