def test_summary_stats_new_test(self): ev = events.TestOutcomeEvent(_test_func, None, result.PASS) reporter = create_plugin_instance() reporter.testOutcome(ev) self.assertIn('passed', reporter.summary_stats) self.assertEqual(reporter.summary_stats['passed'], 1)
def test_summary_stats_total(self): ev = events.TestOutcomeEvent(_test_func, None, result.PASS) reporter = create_plugin_instance() for i in range(0, 20): reporter.testOutcome(ev) self.assertIn('passed', reporter.summary_stats) self.assertEqual(reporter.summary_stats['total'], 20)
def addUnexpectedSuccess(self, test): """Test case resulted in unexpected success. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, PASS) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event)
def addExpectedFailure(self, test, err): """Test case resulted in expected failure. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, FAIL, err, expected=True) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event)
def addSkip(self, test, reason): """Test case was skipped. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, SKIP, reason=reason) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event)
def addError(self, test, err): """Test case resulted in error. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, ERROR, err) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event)
def addSubTest(self, test, subtest, err): """Called at the end of a subtest. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(subtest, self, SUBTEST, err) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event)
def test_outcome_processing_successful_test(self): test_function = _test_func ev = events.TestOutcomeEvent(test_function, None, result.PASS) reporter = create_plugin_instance() reporter.testOutcome(ev) self.assertEqual(len(reporter.test_results), 1, 'Actual contents: %s' % reporter.test_results) test_result = reporter.test_results[0] self.assertEqual(test_result['result'], result.PASS) self.assertEqual(test_result['name'], test_function.__name__) self.assertEqual(test_result['description'], test_function.__doc__) self.assertIsNone(test_result['traceback'])
def test_outcome_with_error_test_result(self): test_function = _test_func_fail try: test_function() except: exc_info = sys.exc_info() ev = events.TestOutcomeEvent(test_function, None, result.ERROR, exc_info=exc_info) reporter = create_plugin_instance() reporter.testOutcome(ev) self.assertEqual(len(reporter.test_results), 1, 'Actual contents: %s' % reporter.test_results) test_result = reporter.test_results[0] self.assertEqual(test_result['result'], result.ERROR) self.assertEqual(test_result['name'], test_function.__name__) self.assertEqual(test_result['description'], test_function.__doc__) self.assertIsNotNone(test_result['traceback']) self.assertIn('assert 1 == 2', test_result['traceback'])