How to use _prepare_callback method in unittest-xml-reporting

Best Python code snippet using unittest-xml-reporting_python

result.py

Source:result.py Github

copy

Full Screen

...111 self.subtests = {}112 self.callback = None113 self.infoclass = _TestInfo114 self.report_files = []115 def _prepare_callback(self, test_info, target_list, verbose_str,116 short_str):117 """ Appends a 'info class' to the given target list and sets a118 callback method to be called by stopTest method."""119 target_list.append(test_info)120 def callback():121 """ Print test method outcome to the stream and elapsed time too."""122 test_info.test_finished()123 if self.showAll:124 self.stream.writeln(125 "{} ({:3f})s".format(verbose_str, test_info.elapsed_time))126 elif self.dots:127 self.stream.write(short_str)128 self.callback = callback129 def getDescription(self, test):130 """ Return the test description if not have test name. """131 return str(test)132 def startTest(self, test):133 """ Called before execute each method. """134 self.start_time = time.time()135 TestResult.startTest(self, test)136 if self.showAll:137 self.stream.write(" " + self.getDescription(test))138 self.stream.write(" ... ")139 def _save_output_data(self):140 try:141 self._stdout_data = sys.stdout.getvalue()142 self._stderr_data = sys.stderr.getvalue()143 except AttributeError:144 pass145 def stopTest(self, test):146 """ Called after excute each test method. """147 self._save_output_data()148 TextTestResult.stopTest(self, test)149 self.stop_time = time.time()150 if self.callback and callable(self.callback):151 self.callback()152 self.callback = None153 def addSuccess(self, test):154 """ Called when a test executes successfully. """155 self._save_output_data()156 self._prepare_callback(self.infoclass(self, test), self.successes, "OK", ".")157 @failfast158 def addFailure(self, test, err):159 """ Called when a test method fails. """160 self._save_output_data()161 testinfo = self.infoclass(self, test, self.infoclass.FAILURE, err)162 self._prepare_callback(testinfo, self.failures, "FAIL", "F")163 @failfast164 def addError(self, test, err):165 """" Called when a test method raises an error. """166 self._save_output_data()167 testinfo = self.infoclass(self, test, self.infoclass.ERROR, err)168 self._prepare_callback(testinfo, self.errors, 'ERROR', 'E')169 def addSubTest(self, testcase, test, err):170 """ Called when a subTest completes. """171 self._save_output_data()172 # TODO: should ERROR cases be considered here too?173 if err is None:174 testinfo = self.infoclass(self, testcase, self.infoclass.SUCCESS, err, subTest=test)175 self._prepare_callback(testinfo, self.successes, "OK", ".")176 else:177 testinfo = self.infoclass(self, testcase, self.infoclass.FAILURE, err, subTest=test)178 self._prepare_callback(testinfo, self.failures, "FAIL", "F")179 test_id_components = str(testcase).rstrip(')').split(' (')180 test_id = test_id_components[1] + '.' + test_id_components[0]181 if test_id not in self.subtests:182 self.subtests[test_id] = []183 self.subtests[test_id].append(testinfo)184 def addSkip(self, test, reason):185 """" Called when a test method was skipped. """186 self._save_output_data()187 testinfo = self.infoclass(self, test, self.infoclass.SKIP, reason)188 self._prepare_callback(testinfo, self.skipped, "SKIP", "S")189 def printErrorList(self, flavour, errors):190 """191 Writes information about the FAIL or ERROR to the stream.192 """193 for test_info in errors:194 self.stream.writeln(self.separator1)195 self.stream.writeln(196 '{} [{:3f}s]: {}'.format(flavour, test_info.elapsed_time,197 test_info.test_id)198 )199 self.stream.writeln(self.separator2)200 self.stream.writeln('%s' % test_info.get_error_info())201 def _get_info_by_testcase(self):202 """ Organize test results by TestCase module. """...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run unittest-xml-reporting automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful