def test_initialize_test_file_report(self, project_session, test_utils): _, project = project_session.activate() # create a test test_file = test_utils.random_string() content = 'def test_one(data):\n' \ ' pass\n' \ 'def test_two(data):\n' \ ' pass' test_utils.create_test(project, test_file, content) # create test file reportdir execution = test_file timestamp = utils.get_timestamp() exec_dir = create_execution_directory(project, test_file, timestamp) test_file_reportdir = create_test_file_report_dir( exec_dir, test_file, '') # initialize report for test file test_report.initialize_test_file_report(test_file, ['test_one', 'test_two'], '', test_file_reportdir, '', '') test_file_report = test_report.get_test_file_report_json( project, execution, timestamp, test_file) assert len(test_file_report) == 2 assert any( t['test'] == 'test_one' and t['result'] == ResultsEnum.PENDING for t in test_file_report) assert any( t['test'] == 'test_two' and t['result'] == ResultsEnum.PENDING for t in test_file_report)
def test_create_report_directory_test_without_set(self, project_session): testdir, project = project_session.activate() timestamp = utils.get_timestamp() test_name = 'testing_report_001' exec_dir = create_execution_directory(project, test_name, timestamp) directory = create_test_file_report_dir(exec_dir, test_name, '') assert os.path.isdir(directory)
def test_create_execution_directory_suite_parents(self, project_session): testdir, project = project_session.activate() timestamp = utils.get_timestamp() suite_name = 'a.b.suite_execution_directory' directory = create_execution_directory(project, suite_name, timestamp) path = os.path.join(project_session.path, 'reports', suite_name, timestamp) assert os.path.isdir(path) assert directory == path
def test_create_report_directory_suite(self, project_session): testdir, project = project_session.activate() timestamp = utils.get_timestamp() suite_name = 'suite_foo_002' test_name = 'testing_report_002' exec_dir = create_execution_directory(project, suite_name, timestamp) directory = create_report_directory(exec_dir, test_name, is_suite=True) assert os.path.isdir(directory)
def test_create_execution_directory__for_single_test_with_parents(self, project_session, test_utils): _, project = project_session.activate() timestamp = utils.get_timestamp() test_name = f'foo.bar.{test_utils.random_string()}' directory = create_execution_directory(project, test_name, timestamp) path = os.path.join(project_session.path, 'reports', test_name, timestamp) assert os.path.isdir(path) assert directory == path
def _create_execution_directory(self): """Generate the execution report directory""" if self.is_suite: directory = exec_report.create_execution_directory( self.project, self.suite_name, self.timestamp) else: directory = exec_report.create_execution_dir_single_test( self.project, self.test_name, self.timestamp) return directory
def test_generate_report_with_env(self, project_session): _, project = project_session.activate() timestamp = utils.get_timestamp() test_name = 'testing_report_003' suite_name = 'suite_foo_003' exec_dir = create_execution_directory(project, suite_name, timestamp) report_dir = create_report_directory(exec_dir, test_name, is_suite=True) test_data = { 'env': { 'name': 'env01', 'url': '1.1.1.1' }, 'var2': 'value2' } test_data = test_runner.Data(test_data) result = { 'result': 'success', 'errors': [], 'description': 'description of the test', 'steps': [{ 'message': 'step1', 'screenshot': None, 'error': None }, { 'message': 'step2', 'screenshot': None, 'error': None }], 'test_elapsed_time': 22.22, 'test_timestamp': '2018.02.04.02.16.42.729', 'browser': 'chrome', 'browser_full_name': '', 'set_name': 'set_001', } generate_report(report_dir, test_name, test_data, result) path = os.path.join(report_dir, 'report.json') with open(path) as report_file: actual = json.load(report_file) assert len(actual.items()) == 11 assert actual['test_case'] == test_name assert actual['result'] == 'success' assert actual['steps'][0]['message'] == 'step1' assert actual['steps'][1]['message'] == 'step2' assert actual['description'] == 'description of the test' assert actual['errors'] == [] assert actual['test_elapsed_time'] == 22.22 assert actual['test_timestamp'] == '2018.02.04.02.16.42.729' assert actual['browser'] == 'chrome' assert actual['environment'] == 'env01' assert actual['set_name'] == 'set_001' test_data_a = "{'url': '1.1.1.1', 'name': 'env01'}" test_data_b = "{'name': 'env01', 'url': '1.1.1.1'}" assert actual['test_data']['env'] in [test_data_a, test_data_b] assert actual['test_data']['var2'] == "'value2'"
def _create_execution_directory(self): """Generate the execution report directory""" return exec_report.create_execution_directory(self.project.name, self.execution_name, self.timestamp)
def _mock_report_directory(project, execution_name, timestamp): return execution_report.create_execution_directory(project, execution_name, timestamp)