Best Python code snippet using Testify_python
test_case.py
Source:test_case.py
...177 # Once a test case completes we should trigger178 # EVENT_ON_COMPLETE_TEST_CASE event so that we can log/report test case179 # results.180 if not test_case_result.complete:181 test_case_result.end_in_success()182 self.fire_event(self.EVENT_ON_COMPLETE_TEST_CASE, test_case_result)183 @classmethod184 def in_suite(cls, method, suite_name):185 """Return a bool denoting whether the given method is in the given suite."""186 return suite_name in getattr(method, '_suites', set())187 def suites(self, method=None):188 """Returns the suites associated with this test case and, optionally, the given method."""189 suites = set(getattr(self, '_suites', []))190 if method is not None:191 suites |= getattr(method, '_suites', set())192 return suites193 def results(self):194 """Available after calling `self.run()`."""195 if self._stage != self.STAGE_CLASS_TEARDOWN:196 raise RuntimeError('results() called before tests have executed')197 return list(self.__all_test_results)198 def method_excluded(self, method):199 """Given this TestCase's included/excluded suites, is this test method excluded?200 Returns a set of the excluded suites that the argument method is in, or an empty201 suite if none.202 """203 method_suites = set(getattr(method, '_suites', set()))204 return (self.__suites_exclude & method_suites)205 def __run_test_methods(self, class_fixture_failures):206 """Run this class's setup fixtures / test methods / teardown fixtures.207 These are run in the obvious order - setup and teardown go before and after,208 respectively, every test method. If there was a failure in the class_setup209 phase, no method-level fixtures or test methods will be run, and we'll eventually210 skip all the way to the class_teardown phase. If a given test method is marked211 as disabled, neither it nor its fixtures will be run. If there is an exception212 during the setup phase, the test method will not be run and execution213 will continue with the teardown phase.214 """215 for test_method in self.runnable_test_methods():216 result = TestResult(test_method)217 # Sometimes, test cases want to take further action based on218 # results, e.g. further clean-up or reporting if a test method219 # fails. (Yelp's Selenium test cases do this.) If you need to220 # programatically inspect test results, you should use221 # self.results().222 # NOTE: THIS IS INCORRECT -- im_self is shared among all test223 # methods on the TestCase instance. This is preserved for backwards224 # compatibility and should be removed eventually.225 try:226 # run "on-run" callbacks. e.g. print out the test method name227 self.fire_event(self.EVENT_ON_RUN_TEST_METHOD, result)228 result.start()229 self.__all_test_results.append(result)230 # if class setup failed, this test has already failed.231 self._stage = self.STAGE_CLASS_SETUP232 for exc_info in class_fixture_failures:233 result.end_in_failure(exc_info)234 if result.complete:235 continue236 # first, run setup fixtures237 self._stage = self.STAGE_SETUP238 with self.__test_fixtures.instance_context() as fixture_failures:239 # we haven't had any problems in class/instance setup, onward!240 if not fixture_failures:241 self._stage = self.STAGE_TEST_METHOD242 result.record(test_method)243 self._stage = self.STAGE_TEARDOWN244 # maybe something broke during teardown -- record it245 for exc_info in fixture_failures:246 result.end_in_failure(exc_info)247 if result.interrupted:248 raise Interruption249 # if nothing's gone wrong, it's not about to start250 if not result.complete:251 result.end_in_success()252 finally:253 self.fire_event(self.EVENT_ON_COMPLETE_TEST_METHOD, result)254 if not result.success:255 self.failure_count += 1256 if self.failure_limit and self.failure_count >= self.failure_limit:257 break258 def addfinalizer(self, teardown_func):259 if self._stage in (self.STAGE_SETUP, self.STAGE_TEST_METHOD, self.STAGE_TEARDOWN):260 self.__extra_test_teardowns.append(teardown_func)261 elif self._stage in (self.STAGE_CLASS_SETUP, self.STAGE_CLASS_TEARDOWN):262 self.__extra_class_teardowns.append(teardown_func)263 else:264 raise RuntimeError('Tried to add a teardown while the test was not being executed.')265 @test_fixtures.class_setup_teardown...
json_log_test.py
Source:json_log_test.py
...42 """43 result = test_result.TestResult(self.extended_test_case.test_method)44 self.json_reporter.test_start(result.to_dict())45 result.start()46 result.end_in_success()47 self.json_reporter.test_complete(result.to_dict())48 assert_equal(True, self.json_reporter.report())49 log_lines = ''.join(50 line for line in51 self.log_file.getvalue().splitlines()52 if line != 'RUN COMPLETE'53 )54 result = json.loads(log_lines)55 assert_equal('extended', result['method']['module'])56 assert_equal('extended ExtendedTestCase.test_method', result['method']['full_name'])57if __name__ == '__main__':...
test_result_serializable_test.py
Source:test_result_serializable_test.py
...12 result = test_result.TestResult(self.null_test_case.test_method)13 json.dumps(result.to_dict())14 result.start()15 json.dumps(result.to_dict())16 result.end_in_success()17 json.dumps(result.to_dict())18 def test_not_garbled_by_serialization(self):19 """Make sure that converting to JSON and back results in the same dictionary."""20 result = test_result.TestResult(self.null_test_case.test_method)21 assert_equal(22 result.to_dict(),23 json.loads(json.dumps(result.to_dict()))24 )25 result.start()26 assert_equal(27 result.to_dict(),28 json.loads(json.dumps(result.to_dict()))29 )30 result.end_in_success()31 assert_equal(32 result.to_dict(),33 json.loads(json.dumps(result.to_dict()))34 )35if __name__ == '__main__':...
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!!