Best Python code snippet using Testify_python
test_case_time_log_test.py
Source:test_case_time_log_test.py
...16 super(MyStringIO).close()17def _mock_conf_file_open(fname, mode='w'):18 return MyStringIO()19@contextlib.contextmanager20def mock_conf_files():21 with mock.patch.object(six.moves.builtins, 'open', _mock_conf_file_open):22 yield23start_time = datetime.datetime(2014, 12, 17, 12, 38, 37, 0)24end_time = datetime.datetime(2014, 12, 17, 15, 38, 37, 0)25output_str = (26 """{"normalized_run_time": "10800.00s", """27 """"complete": true, "start_time": %s, """28 """"runner_id": null, "failure": null, "run_time": %s, """29 """"previous_run": null, "success": null, "exception_info": null, """30 """"interrupted": null, """31 """"method": {"full_name": "testify.test_case TestCase.run", """32 """"fixture_type": null, "class": "TestCase", """33 """"module": "testify.test_case", "name": "run"}, """34 """"exception_info_pretty": null, "end_time": %s, "error": null, """35 """"exception_only": ""}\n""" % (time.mktime(start_time.timetuple()),36 str(time.mktime(end_time.timetuple()) - time.mktime(start_time.timetuple())),37 time.mktime(end_time.timetuple())))38class TestCaseJSONReporterTestCase(TestCase):39 def set_options(self):40 parser = OptionParser()41 add_command_line_options(parser)42 self.options, args = parser.parse_args([43 '--test-case-results', 'test_case_dummy.json'44 ])45 def test_json_reporter_reports(self):46 self.set_options()47 with mock_conf_files():48 self.reporter = TestCaseJSONReporter(self.options)49 test_case = TestCase()50 fake_test_result = TestResult(test_case.run)51 with mock.patch.object(52 datetime, 'datetime', **{'now.return_value': start_time}53 ):54 fake_test_result.start()55 with mock.patch.object(datetime, 'datetime', **{'now.return_value': end_time}):56 fake_test_result._complete()57 self.reporter.test_case_complete(fake_test_result.to_dict())58 assert_equal(59 json.loads(self.reporter.log_file.getvalue()),60 json.loads(output_str),61 )
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!!