Best Python code snippet using green
test_runner.py
Source:test_runner.py
...137 return138 finally:139 if test_suite is not None:140 scheduler.test_done()141 def _add_skipped_tests(self, test_suite, results, start_time, num_tests, output_file_name):142 for name in test_suite.test_names:143 #TODO: set case not run as failed case144 results[name]['status'] = FAILED145 self._add_results(test_suite, results, start_time, num_tests, output_file_name)146 def _run_test_suite(self,147 test_suite,148 write_stdout,149 num_tests):150 """151 Run the actual test suite152 """153 #output_file = None154 devNull = None155 start_time = ostools.get_time()156 results = self._fail_suite(test_suite)157 try:158 if write_stdout:159 """160 If write_stdout enable, use stdout, showing log in terminal161 """162 #self._local.output = Tee([self._stdout])163 self._local.output = self._stdout164 else:165 """166 Open a dummy file os.devnull for writing log file to it, 167 not showing log in terminal168 If you want to save log in a file, use code below:169 >>> output_file = open("xxx.log", "w")170 >>> self._local.output = Tee([output_file])171 """172 devNull = open(os.devnull, "w")173 self._local.output = devNull174 #self._local.output = Tee([devNull])175 results = test_suite.run()176 except KeyboardInterrupt:177 self._add_skipped_tests(test_suite, results, start_time, num_tests, test_suite.test_result_file)178 raise KeyboardInterrupt179 except:180 if self._dont_catch_exceptions:181 raise182 with self._stdout_lock():183 traceback.print_exc()184 finally:185 self._local.output = self._stdout186 if devNull != None:187 devNull.close() 188 #for fptr in [output_file]:189 # if fptr is None:190 # continue191 # fptr.flush()...
junit.py
Source:junit.py
...53 result = {}54 self._add_passing_tests(result, test_results)55 self._add_failures(result, test_results)56 self._add_errors(result, test_results)57 self._add_skipped_tests(result, test_results)58 return result59 @staticmethod60 def _add_passing_tests(collection, test_results):61 for each_test in test_results.passing:62 key = JUnitXML._suite_name(each_test)63 if key not in collection:64 collection[key] = []65 collection[key].append((Verdict.PASSED, each_test))66 @staticmethod67 def _suite_name(test):68 return "%s.%s" % (test.module, test.class_name)69 @staticmethod70 def _add_failures(collection, test_results):71 for each_test, failure in test_results.failures:72 key = JUnitXML._suite_name(each_test)73 if key not in collection:74 collection[key] = []75 collection[key].append((Verdict.FAILED, each_test, failure))76 @staticmethod77 def _add_errors(collection, test_results):78 for each_test, error in test_results.errors:79 key = JUnitXML._suite_name(each_test)80 if key not in collection:81 collection[key] = []82 collection[key].append((Verdict.ERROR, each_test, error))83 @staticmethod84 def _add_skipped_tests(collection, test_results):85 for each_test, reason in test_results.skipped:86 key = JUnitXML._suite_name(each_test)87 if key not in collection:88 collection[key] = []89 collection[key].append((Verdict.SKIPPED, each_test, reason))90 def _convert_suite(self, results, name, suite):91 xml_suite = Element(JUnitDialect.TEST_SUITE)92 xml_suite.set(JUnitDialect.NAME, name)93 xml_suite.set(JUnitDialect.TEST_COUNT, str(len(suite)))94 xml_suite.set(95 JUnitDialect.FAILURE_COUNT,96 str(self._count_test_with_verdict(Verdict.FAILED, suite)),97 )98 xml_suite.set(...
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!!