def run(self, test): """Run tests. :param test: A unittest TestSuite or TestClass. :returns: Test result Fires :func:`startTestRun` and :func:`stopTestRun` hooks. """ result = self._makeResult() executor = lambda suite, result: suite(result) startTime = time.time() event = events.StartTestRunEvent(self, test, result, startTime, executor) self.session.hooks.startTestRun(event) # allows startTestRun to modify test suite test = event.suite # ... and test execution executor = event.executeTests try: if not event.handled: executor(test, result) finally: stopTime = time.time() timeTaken = stopTime - startTime event = events.StopTestRunEvent(self, result, stopTime, timeTaken) self.session.hooks.stopTestRun(event) self.session.hooks.afterTestRun(event) return result
def test_writes_xml_file_at_end(self): test = self.case('test') test(self.result) event = events.StopTestRunEvent(None, self.result, 1, 1) self.plugin.stopTestRun(event) with open(self.plugin.path, 'r') as fh: tree = ET.parse(fh).getroot() self.assertEqual(len(tree.findall('testcase')), 1) case = tree.find('testcase') assert 'time' in case.attrib assert 'classname' in case.attrib self.assertEqual(case.get('name'), 'test') self.assertEqual(tree.get('errors'), '0') self.assertEqual(tree.get('failures'), '0') self.assertEqual(tree.get('skipped'), '0') self.assertEqual(tree.get('tests'), '1') assert 'time' in tree.attrib
def test_writes_xml_file_at_end(self): test = self.case("test") test(self.result) event = events.StopTestRunEvent(None, self.result, 1, 1) self.plugin.stopTestRun(event) with open(self.plugin.path, "r") as fh: tree = ET.parse(fh).getroot() self.assertEqual(len(tree.findall("testcase")), 1) case = tree.find("testcase") assert "time" in case.attrib assert "classname" in case.attrib self.assertEqual(case.get("name"), "test") self.assertEqual(tree.get("errors"), "0") self.assertEqual(tree.get("failures"), "0") self.assertEqual(tree.get("skipped"), "0") self.assertEqual(tree.get("tests"), "1") assert "time" in tree.attrib