Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly end the test when expects has an error within teardown test. #882

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mobly/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ def exec_one_test(self, test_name, test_method, record=None):
else:
# Check if anything failed by `expects`.
if before_count < expects.recorder.error_count:
tr_record.test_error()
teardown_test_failed = True
except (signals.TestFailure, AssertionError) as e:
tr_record.test_fail(e)
Expand Down
22 changes: 22 additions & 0 deletions tests/mobly/base_test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,28 @@ def test_something(self):
"Requested 1, Skipped 0")
self.assertEqual(bt_cls.results.summary_str(), expected_summary)

def test_teardown_test_expects_error(self):

class MockBaseTest(base_test.BaseTestClass):

def teardown_test(self):
expects.expect_true(False, MSG_EXPECTED_EXCEPTION)

def test_something(self):
pass

bt_cls = MockBaseTest(self.mock_test_cls_configs)
bt_cls.run()
actual_record = bt_cls.results.error[0]
self.assertEqual(actual_record.test_name, self.mock_test_name)
self.assertEqual(actual_record.details, MSG_EXPECTED_EXCEPTION)
self.assertIsNone(actual_record.extras)
self.assertFalse(actual_record.extra_errors)
self.assertTrue(actual_record.end_time)
expected_summary = ("Error 1, Executed 1, Failed 0, Passed 0, "
"Requested 1, Skipped 0")
self.assertEqual(bt_cls.results.summary_str(), expected_summary)

def test_teardown_test_executed_if_test_pass(self):
my_mock = mock.MagicMock()

Expand Down