Best Python code snippet using unittest-xml-reporting_python
test_result.py
Source:test_result.py  
...53        self.result = collections.OrderedDict()54        self.successes = []55        self.testinfo = None5657    def _save_output_data(self):58        """59        :return:60        """61        try:62            self._stdout_data = Var.case_message63            Var.case_message = ""64            Var.case_step_index = 065            Var.case_snapshot_index = 066        except AttributeError as e:67            pass6869    def startTest(self, test):70        """71        :param test:72        :return:73        """74        super(TestResult, self).startTest(test)75        self.start_time = time.time()76        Var.test_case_steps = {}77        Var.is_debug = False7879    def stopTest(self, test):80        """81        :param test:82        :return:83        """84        self._save_output_data()85        unittest.TextTestResult.stopTest(self, test)86        self.stop_time = time.time()87        self.report = test.report88        self.testinfo.start_time = self.start_time89        self.testinfo.stop_time = self.stop_time90        self.testinfo.report = self.report91        self.testinfo.test_case_steps = Var.test_case_steps92        if test.module not in self.result.keys():93            self.result[test.module] = []94        self.result[test.module].append(self.testinfo)95        self.testinfo = None96        Var.test_case_steps = {}97        Var.is_debug = False9899    def addSuccess(self, test):100        """101        :param test:102        :return:103        """104        super(TestResult, self).addSuccess(test)105        self._save_output_data()106        self.testinfo = TestInfo(test, TestInfo.SUCCESS)107        self.successes.append(test)108109    def addError(self, test, err):110        """111        :param test:112        :return:113        """114        super(TestResult, self).addError(test, err)115        self._save_output_data()116        _exc_str = self._exc_info_to_string(err, test)117        self.testinfo = TestInfo(test, TestInfo.ERROR, _exc_str)118        log_error(' case: {}'.format(self.testinfo.case_path), False)119        log_error(_exc_str, False)120121    def addFailure(self, test, err):122        """123        :param test:124        :return:125        """126        super(TestResult, self).addFailure(test, err)127        self._save_output_data()128        _exc_str = self._exc_info_to_string(err, test)129        self.testinfo = TestInfo(test, TestInfo.FAILURE, _exc_str)130        log_error(' case: {}'.format(self.testinfo.case_path), False)131        log_error(_exc_str, False)132133    def addSkip(self, test, reason):134        """135        :param test:136        :return:137        """138        super(TestResult, self).addSkip(test, reason)139        self._save_output_data()140        self.testinfo = TestInfo(test, TestInfo.SKIP)141142    def addExpectedFailure(self, test, err):143        """144        :param test:145        :param err:146        :return:147        """148        super(TestResult, self).addFailure(test, err)149        self._save_output_data()150        _exc_str = self._exc_info_to_string(err, test)151        self.testinfo = TestInfo(test, TestInfo.FAILURE, _exc_str)152        log_error(' case: {}'.format(self.testinfo.case_path), False)
...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
