Best Python code snippet using Testify_python
test_case.py
Source:test_case.py
...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)...
test_result.py
Source:test_result.py
...59 if hasattr(exception, '_testify_exc_tb'):60 exc_info = (type(exception), exception, exception._testify_exc_tb)61 else:62 exc_info = sys.exc_info()63 self.end_in_failure(exc_info)64 if self.debug:65 self._postmortem(exc_info)66 return False67 else:68 return True69 def _postmortem(self, exc_info):70 _, _, traceback = exc_info71 print("\nDEBUGGER")72 print(self.format_exception_info())73 try:74 detected_postmortem_tool = __import__('ipdb').post_mortem75 except ImportError:76 detected_postmortem_tool = __import__('pdb').post_mortem77 detected_postmortem_tool(traceback)78 def _complete(self):79 self.complete = True80 self.end_time = datetime.datetime.now()81 self.run_time = self.end_time - self.start_time82 def end_in_failure(self, exception_info):83 if not self.complete:84 self._complete()85 self.success = False86 if isinstance(exception_info[1], AssertionError):87 # test failure, kinda expect these vs. unknown errors88 self.failure = True89 elif isinstance(exception_info[1], KeyboardInterrupt):90 self.interrupted = True91 else:92 self.error = True93 self.exception_infos.append(exception_info)94 def end_in_success(self):95 if not self.complete:96 self._complete()...
test_result_test.py
Source:test_result_test.py
...32 f_globals = {'__testify': True} if testify_frame else {}33 tb.configure_mock(**{'tb_frame.f_globals': f_globals})34 tb.tb_next = None35 tb = root_tb.tb_next36 test_result.end_in_failure((AssertionError, 'wat', tb))37 formatted = test_result.format_exception_info()38 assert_equal(formatted, 'Traceback: AssertionError\n')39 # It should format three frames of the stack, starting with the third frame.40 mock_format_exception.assert_called_with(AssertionError, 'wat', tb.tb_next.tb_next, 3)41 @mock.patch('traceback.format_exception', wraps=fake_format_exception)42 def test_format_exception_info_assertion(self, mock_format_exception):43 value, tb = self._append_exc_info(AssertionError)44 formatted = self.test_result.format_exception_info()45 mock_format_exception.assert_called_with(AssertionError, value, tb, 1)46 assert_equal(formatted, 'Traceback: AssertionError\n')47 @mock.patch('traceback.format_exception', wraps=fake_format_exception)48 def test_format_exception_info_error(self, mock_format_exception):49 value, tb = self._append_exc_info(ValueError)50 formatted = self.test_result.format_exception_info()...
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!!