def test_generate_tests_call_outside_of_setup_generated_tests(self): class MockBaseTest(base_test.BaseTestClass): def test_ha(self): self.generate_tests( test_logic=self.logic, name_func=self.name_gen, arg_sets=[(1, 2), (3, 4)]) def name_gen(self, a, b): return 'test_%s_%s' % (a, b) def logic(self, a, b): pass bt_cls = MockBaseTest(self.mock_test_cls_configs) bt_cls.run() actual_record = bt_cls.results.error[0] utils.validate_test_result(bt_cls.results) self.assertEqual(actual_record.test_name, "test_ha") self.assertEqual( actual_record.details, '"generate_tests" cannot be called outside of setup_generated_tests' ) 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_is_all_pass_negative(self): s = signals.TestFailure(self.details, self.float_extra) record1 = records.TestResultRecord(self.tn) record1.test_begin() record1.test_fail(s) record2 = records.TestResultRecord(self.tn) record2.test_begin() record2.test_error(s) tr = records.TestResult() tr.add_record(record1) tr.add_record(record2) utils.validate_test_result(tr) self.assertFalse(tr.is_all_pass)
def test_setup_class_fail_by_exception(self): teardown_class_call_check = mock.MagicMock() on_fail_call_check = mock.MagicMock() class MockBaseTest(base_test.BaseTestClass): def setup_class(self): raise Exception(MSG_EXPECTED_EXCEPTION) def test_something(self): # This should not execute because setup_class failed. never_call() def test_something2(self): # This should not execute because setup_class failed. never_call() def teardown_class(self): # This should execute because the setup_class failure should # have already been recorded. if not self.results.is_all_pass: teardown_class_call_check("heehee") def on_fail(self, test_name, begin_time): on_fail_call_check("haha") bt_cls = MockBaseTest(self.mock_test_cls_configs) bt_cls.run() actual_record = bt_cls.results.error[0] utils.validate_test_result(bt_cls.results) self.assertEqual(actual_record.test_name, "setup_class") self.assertEqual(actual_record.details, MSG_EXPECTED_EXCEPTION) self.assertIsNone(actual_record.extras) expected_summary = ("Error 1, Executed 0, Failed 0, Passed 0, " "Requested 2, Skipped 2") self.assertEqual(bt_cls.results.summary_str(), expected_summary) teardown_class_call_check.assert_called_once_with("heehee") on_fail_call_check.assert_called_once_with("haha")