aboutsummaryrefslogtreecommitdiff
path: root/tests/mobly/records_test.py
diff options
context:
space:
mode:
authorAng Li <angli@google.com>2017-08-11 14:33:55 -0700
committerGitHub <noreply@github.com>2017-08-11 14:33:55 -0700
commit80e97395ebe2384c6a1e6f9eddb04a8a92bfe9d5 (patch)
tree82754d1529b67996580f4a19e3860def9db9c90f /tests/mobly/records_test.py
parente5df6ca2918e21233d3d207207964b82319c9f9d (diff)
downloadmobly-80e97395ebe2384c6a1e6f9eddb04a8a92bfe9d5.tar.gz
Properly record extra errors. (#284)
* Include exception objects in record for tests' procedure functions to consume * Introduce a wrapper class for storing exception objects in record, including info like stacktrace. * Introduce an alias for the main exception. * Mark failed tests as fail despite subsequent errors..
Diffstat (limited to 'tests/mobly/records_test.py')
-rwxr-xr-xtests/mobly/records_test.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/tests/mobly/records_test.py b/tests/mobly/records_test.py
index a5f68db..719f0c8 100755
--- a/tests/mobly/records_test.py
+++ b/tests/mobly/records_test.py
@@ -28,6 +28,7 @@ from tests.lib import utils
class RecordsTest(unittest.TestCase):
"""This test class tests the implementation of classes in mobly.records.
"""
+
def setUp(self):
self.tn = "test_name"
self.details = "Some details about the test execution."
@@ -38,7 +39,8 @@ class RecordsTest(unittest.TestCase):
def tearDown(self):
shutil.rmtree(self.tmp_path)
- def verify_record(self, record, result, details, extras):
+ def verify_record(self, record, result, details, extras, stacktrace=None):
+ record.update_record()
# Verify each field.
self.assertEqual(record.test_name, self.tn)
self.assertEqual(record.result, result)
@@ -58,9 +60,15 @@ class RecordsTest(unittest.TestCase):
d[records.TestResultEnums.RECORD_END_TIME] = record.end_time
d[records.TestResultEnums.RECORD_UID] = None
d[records.TestResultEnums.RECORD_CLASS] = None
- d[records.TestResultEnums.RECORD_EXTRA_ERRORS] = {}
- d[records.TestResultEnums.RECORD_STACKTRACE] = None
+ d[records.TestResultEnums.RECORD_EXTRA_ERRORS] = []
+ d[records.TestResultEnums.RECORD_STACKTRACE] = stacktrace
actual_d = record.to_dict()
+ # Verify stacktrace partially match as stacktraces often have file path
+ # in them.
+ if stacktrace:
+ stacktrace_key = records.TestResultEnums.RECORD_STACKTRACE
+ self.assertTrue(
+ d.pop(stacktrace_key) in actual_d.pop(stacktrace_key))
self.assertDictEqual(actual_d, d)
# Verify that these code paths do not cause crashes and yield non-empty
# results.
@@ -123,16 +131,14 @@ class RecordsTest(unittest.TestCase):
# Verify stacktrace separately if we expect a non-None value.
# Because stacktrace includes file names and line numbers, we can't do
# a simple equality check.
- self.assertTrue('Something failed.' in record.stacktrace)
- self.assertTrue(
- 'in test_result_record_fail_stacktrace\n raise Exception' in
- record.stacktrace)
- record.stacktrace = None
self.verify_record(
record=record,
result=records.TestResultEnums.TEST_RESULT_FAIL,
details='Something failed.',
- extras=None)
+ extras=None,
+ stacktrace='in test_result_record_fail_stacktrace\n '
+ 'raise Exception(\'Something failed.\')\nException: '
+ 'Something failed.\n')
def test_result_record_fail_with_float_extra(self):
record = records.TestResultRecord(self.tn)