From 94a3433f7386f9749f2c5ac0fa7a977cd83b85d2 Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 12 Dec 2022 05:05:18 -0800 Subject: [PATCH 01/14] change the file paths to host path if CONTAINER_MODE is set --- cafy_pytest/plugin.py | 46 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 67404ff..d9cf29e 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -51,9 +51,14 @@ import pluggy import _pytest +#Check if CONTAINER_MODE env variable is set, this mode is set when cafykit scripts are run using docker/podman +CONTAINER_MODE = os.environ.get("CONTAINER_MODE", None) + #Check with CAFYKIT_HOME or GIT_REPO or CAFYAP_REPO environment is set, #if all are set, CAFYAP_REPO takes precedence CAFY_REPO = os.environ.get("CAFYAP_REPO", None) + + setattr(pytest,"allure",allure) if CAFY_REPO is None: #If CAFYAP_REPO is not set, check if GIT_REPO or CAFYKIT_HOME is set @@ -68,11 +73,15 @@ if os.path.exists(os.path.join(CAFY_REPO, 'work', 'pytest_cafy_config.yaml')): os.environ['CAFY_REPO'] = CAFY_REPO print('GIT_REPO variable has been set to correct repo') + if CONTAINER_MODE: + CONTAINER_MODE_CAFY_REPO = os.environ.get("HOST_GIT_REPO", None) else: msg = 'GIT_REPO has not been set to correct repo' pytest.exit(msg) else: os.environ['CAFY_REPO'] = CAFY_REPO + if CONTAINER_MODE: + CONTAINER_MODE_CAFY_REPO = os.environ.get("HOST_CAFYAP_REPO", None) if not CAFY_REPO: msg = "Please set the environment variable GIT_REPO or CAFYKIT_HOME or CAFYAP_REPO " @@ -367,12 +376,20 @@ def pytest_configure(config): if os.path.exists(config.option.workdir): custom_workdir = config.option.workdir work_dir = custom_workdir + if CONTAINER_MODE: + if os.environ.get("HOST_WORK_DIR", None): + container_mode_work_dir = os.environ.get("HOST_WORK_DIR") else: print('workdir path not found: {}'.format(config.option.workdir)) pytest.exit('workdir path not found') else: if CAFY_REPO: work_dir = os.path.join(CAFY_REPO, 'work', "archive", work_dir_name) + if CONTAINER_MODE: + if CONTAINER_MODE_CAFY_REPO: + container_mode_work_dir = os.path.join( + CONTAINER_MODE_CAFY_REPO, 'work', "archive", work_dir_name) + else: if os.path.exists(config.option.reportdir): work_dir = os.path.join(config.option.reportdir, work_dir_name) @@ -545,7 +562,10 @@ def pytest_configure(config): reporter = TerminalReporter(config, sys.stdout) #reporter.write_line("all.log location: %s" %CafyLog.work_dir) reporter.write_line("Virtual Env: %s" %(os.getenv("VIRTUAL_ENV"))) - reporter.write_line("Complete Log Location: %s/all.log" %CafyLog.work_dir) + if CONTAINER_MODE: + reporter.write_line("Complete Log Location: %s/all.log" % container_mode_work_dir) + else: + reporter.write_line("Complete Log Location: %s/all.log" %CafyLog.work_dir) reporter.write_line("Registration Id: %s" % CafyLog.registration_id) @@ -793,6 +813,8 @@ def __init__(self, email_addr_list, email_from, email_from_passwd, #self.archive_name = CafyLog.work_dir + '.zip' #self.archive = os.path.join(CafyLog.work_dir, self.archive_name) self.archive = CafyLog.work_dir + if CONTAINER_MODE: + self.host_archive = container_mode_work_dir self.email_report = os.path.join(CafyLog.work_dir, email_report) else: @@ -1748,8 +1770,14 @@ def pytest_terminal_summary(self, terminalreporter): self.tabulate_result = tabulate(temp_list, headers=headers[:], tablefmt='grid') terminalreporter.write_line(self.tabulate_result) self.dump_model_coverage_report() - terminalreporter.write_line("Results: {work_dir}".format(work_dir=CafyLog.work_dir)) - terminalreporter.write_line("Reports: {allure_html_report}".format(allure_html_report=self.allure_html_report)) + if CONTAINER_MODE: + terminalreporter.write_line("Results: {work_dir}".format(work_dir=container_mode_work_dir)) + terminalreporter.write_line( + "Reports: {allure_html_report}".format(allure_html_report=self.host_allure_html_report)) + else: + terminalreporter.write_line("Results: {work_dir}".format(work_dir=CafyLog.work_dir)) + + terminalreporter.write_line("Reports: {allure_html_report}".format(allure_html_report=self.allure_html_report)) self._generate_email_report(terminalreporter) @@ -1856,9 +1884,17 @@ def _generate_allure_report(self): CafyLog.htmlfile_link = allure_report allure_html_report = os.path.join(_CafyConfig.allure_server,allure_report.strip("/")) self.allure_html_report = allure_html_report + if CONTAINER_MODE: + host_allure_report_dir = os.path.join(self.host_archive,"reports") + host_allure_report = os.path.join(host_allure_report_dir,"index.html") + host_allure_html_report = os.path.join(_CafyConfig.allure_server,host_allure_report.strip("/")) + self.host_allure_html_report = host_allure_html_report os.system(cmd) #print("Report Generated at: {allure_report}".format(allure_report=allure_report)) - self.log.info("Report: {allure_html_report}".format(allure_html_report=allure_html_report)) + if CONTAINER_MODE: + self.log.info("Report: {allure_html_report}".format(allure_html_report=host_allure_html_report)) + else: + self.log.info("Report: {allure_html_report}".format(allure_html_report=allure_html_report)) _CafyConfig.summary["allure2"] = { "commandline" : cmd, "html" : allure_html_report, @@ -2021,6 +2057,8 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc except Exception: self.git_commit_id = None self.archive = CafyLog.work_dir + if CONTAINER_MODE: + self.host_archive = container_mode_work_dir # summary result passed_list = self.terminalreporter.getreports('passed') failed_list = self.terminalreporter.getreports('failed') From 276d4553c8d28d95b285ee0c938da5ddbfa6ff95 Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 12 Dec 2022 17:50:28 -0800 Subject: [PATCH 02/14] print statement --- cafy_pytest/plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index d9cf29e..5d6299d 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -75,6 +75,7 @@ print('GIT_REPO variable has been set to correct repo') if CONTAINER_MODE: CONTAINER_MODE_CAFY_REPO = os.environ.get("HOST_GIT_REPO", None) + print (f"CONTAINER_MODE_CAFY_REPO = {CONTAINER_MODE_CAFY_REPO}") else: msg = 'GIT_REPO has not been set to correct repo' pytest.exit(msg) From c32f9d38fe573314b5cdab1490b14d8ec59ff8c3 Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 12 Dec 2022 17:59:50 -0800 Subject: [PATCH 03/14] added container_work_Dir variable to CafyLog class --- cafy_pytest/plugin.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 5d6299d..0e3c0d8 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -394,11 +394,16 @@ def pytest_configure(config): else: if os.path.exists(config.option.reportdir): work_dir = os.path.join(config.option.reportdir, work_dir_name) + if CONTAINER_MODE: + if os.environ.get("HOST_REPORT_DIR", None): + container_mode_work_dir = os.environ.get("HOST_REPORT_DIR") else: print('reportdir path not found: {}'.format(config.option.reportdir)) pytest.exit('reportdir path not found') CafyLog.work_dir = work_dir + if CONTAINER_MODE: + CafyLog.container_mode_work_dir = container_mode_work_dir #Set CafyLog.work_dir option for all.log CafyLog.work_dir = work_dir _setup_env() @@ -564,7 +569,7 @@ def pytest_configure(config): #reporter.write_line("all.log location: %s" %CafyLog.work_dir) reporter.write_line("Virtual Env: %s" %(os.getenv("VIRTUAL_ENV"))) if CONTAINER_MODE: - reporter.write_line("Complete Log Location: %s/all.log" % container_mode_work_dir) + reporter.write_line("Complete Log Location: %s/all.log" % CafyLog.container_mode_work_dir) else: reporter.write_line("Complete Log Location: %s/all.log" %CafyLog.work_dir) reporter.write_line("Registration Id: %s" % CafyLog.registration_id) @@ -815,7 +820,7 @@ def __init__(self, email_addr_list, email_from, email_from_passwd, #self.archive = os.path.join(CafyLog.work_dir, self.archive_name) self.archive = CafyLog.work_dir if CONTAINER_MODE: - self.host_archive = container_mode_work_dir + self.host_archive = Cafylog.container_mode_work_dir self.email_report = os.path.join(CafyLog.work_dir, email_report) else: @@ -1772,7 +1777,7 @@ def pytest_terminal_summary(self, terminalreporter): terminalreporter.write_line(self.tabulate_result) self.dump_model_coverage_report() if CONTAINER_MODE: - terminalreporter.write_line("Results: {work_dir}".format(work_dir=container_mode_work_dir)) + terminalreporter.write_line("Results: {work_dir}".format(work_dir=CafyLog.container_mode_work_dir)) terminalreporter.write_line( "Reports: {allure_html_report}".format(allure_html_report=self.host_allure_html_report)) else: @@ -2059,7 +2064,7 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc self.git_commit_id = None self.archive = CafyLog.work_dir if CONTAINER_MODE: - self.host_archive = container_mode_work_dir + self.host_archive = CafyLog.container_mode_work_dir # summary result passed_list = self.terminalreporter.getreports('passed') failed_list = self.terminalreporter.getreports('failed') From 7aa911c48a5d776ef466f214e560616e40457661 Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 12 Dec 2022 18:02:18 -0800 Subject: [PATCH 04/14] monor correction --- cafy_pytest/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 0e3c0d8..e34cebc 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -820,7 +820,7 @@ def __init__(self, email_addr_list, email_from, email_from_passwd, #self.archive = os.path.join(CafyLog.work_dir, self.archive_name) self.archive = CafyLog.work_dir if CONTAINER_MODE: - self.host_archive = Cafylog.container_mode_work_dir + self.host_archive = CafyLog.container_mode_work_dir self.email_report = os.path.join(CafyLog.work_dir, email_report) else: From b19c73c82908c48b97a16ea49c0121adfbd40735 Mon Sep 17 00:00:00 2001 From: shreyash Date: Thu, 12 Jan 2023 15:27:37 -0800 Subject: [PATCH 05/14] archive value on email report to be shown as host path --- cafy_pytest/plugin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index e34cebc..02735e6 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -75,7 +75,6 @@ print('GIT_REPO variable has been set to correct repo') if CONTAINER_MODE: CONTAINER_MODE_CAFY_REPO = os.environ.get("HOST_GIT_REPO", None) - print (f"CONTAINER_MODE_CAFY_REPO = {CONTAINER_MODE_CAFY_REPO}") else: msg = 'GIT_REPO has not been set to correct repo' pytest.exit(msg) @@ -404,6 +403,7 @@ def pytest_configure(config): CafyLog.work_dir = work_dir if CONTAINER_MODE: CafyLog.container_mode_work_dir = container_mode_work_dir + print (f"container_mode_work_dir: {CafyLog.container_mode_work_dir}") #Set CafyLog.work_dir option for all.log CafyLog.work_dir = work_dir _setup_env() @@ -884,7 +884,7 @@ def _generate_with_template(self, terminalreporter): cafy_kwargs = {'terminalreporter': terminalreporter, 'testcase_dict': self.testcase_dict, 'testcase_failtrace_dict':self.testcase_failtrace_dict, - 'archive': self.archive, + 'archive': self.host_archive if CONTAINER_MODE else self.archive, 'topo_file': self.topo_file} report = CafyReportData(**cafy_kwargs) setattr(report,"tabulate_html", self.tabulate_html) @@ -2019,6 +2019,7 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc # Basic details option = self.terminalreporter.config.option self.script_list = option.file_or_dir + # TODO check if CONTAINER_MODE and then set the above script_list variable accordingly self.title = ' '.join(self.script_list) self.image = os.getenv("IMAGE", "Unknown") if os.environ.get("BUILD_URL"): @@ -2055,14 +2056,18 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc self.testbed = None self.registration_id = CafyLog.registration_id self.submitter = EmailReport.USER - self.cafy_repo = EmailReport.CAFY_REPO + self.cafy_repo = EmailReport.CAFY_REPO if not CONTAINER_MODE else CONTAINER_MODE_CAFY_REPO + #TODO: check on cafy_Repo variable value self.topo_file = topo_file + #TODO: topo_file variable needs to print host path for CONTAINER mode self.run_dir = self.terminalreporter.startdir.strpath + # TODO: run_dir variable needs to print host path for CONTAINER mode try: self.git_commit_id = subprocess.check_output(['git', 'rev-parse', 'origin/master'], timeout=5).decode("utf-8").replace('\n', '') except Exception: self.git_commit_id = None self.archive = CafyLog.work_dir + #TODO: archive variable value for CONTAINER mode if CONTAINER_MODE: self.host_archive = CafyLog.container_mode_work_dir # summary result From 7f140af1788a3d4b9f1a78ef03f053674c2401d6 Mon Sep 17 00:00:00 2001 From: shreyash Date: Thu, 12 Jan 2023 15:40:29 -0800 Subject: [PATCH 06/14] minor change --- cafy_pytest/plugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 02735e6..fd0ed3f 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -332,6 +332,7 @@ def _requests_retry(logger, url, method, data=None, files=None, headers=None, t @pytest.hookimpl(tryfirst=True) def pytest_configure(config): + print (f"config: {config}") config._environment = [] email_list = config.option.email_list email_from = config.option.email_from @@ -877,7 +878,7 @@ def _generate_with_template(self, terminalreporter): cafy_kwargs = {'terminalreporter': terminalreporter, 'testcase_dict': self.testcase_dict, 'testcase_failtrace_dict':self.testcase_failtrace_dict, - 'archive': self.archive, + 'archive': self.host_archive if CONTAINER_MODE else self.archive, 'topo_file': self.topo_file, 'hybrid_mode_status_dict':self.hybrid_mode_status_dict} else: From 2438f3e7ed86baee523071687ee657f11bb6a6c8 Mon Sep 17 00:00:00 2001 From: shreyash Date: Thu, 12 Jan 2023 16:13:34 -0800 Subject: [PATCH 07/14] minor print changes --- cafy_pytest/plugin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index fd0ed3f..90e9550 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -874,6 +874,8 @@ def _sendemail(self): def _generate_with_template(self, terminalreporter): '''generate report using template''' #additional field of hybrid_mode_status_dict for html template in order display mode of each testcase in email report + print (f"########CONTAINER_MODE = {CONTAINER_MODE}") + print (f"########self.host_archive = {self.host_archive}") if hasattr(CafyLog,"hybrid_mode_dict") and CafyLog.hybrid_mode_dict.get('mode',None): cafy_kwargs = {'terminalreporter': terminalreporter, 'testcase_dict': self.testcase_dict, From 0409f4ff5797448fcfed00c74f2f04c8c16d384c Mon Sep 17 00:00:00 2001 From: shreyash Date: Thu, 12 Jan 2023 16:31:30 -0800 Subject: [PATCH 08/14] archive path fix --- cafy_pytest/plugin.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 90e9550..6087214 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -2069,10 +2069,7 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc self.git_commit_id = subprocess.check_output(['git', 'rev-parse', 'origin/master'], timeout=5).decode("utf-8").replace('\n', '') except Exception: self.git_commit_id = None - self.archive = CafyLog.work_dir - #TODO: archive variable value for CONTAINER mode - if CONTAINER_MODE: - self.host_archive = CafyLog.container_mode_work_dir + self.archive = archive # summary result passed_list = self.terminalreporter.getreports('passed') failed_list = self.terminalreporter.getreports('failed') From cc5108235549e011b9f618809f01824d7405975f Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 20 Feb 2023 16:59:27 -0800 Subject: [PATCH 09/14] TODO comment --- cafy_pytest/plugin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 6087214..6c4eba0 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -1891,6 +1891,7 @@ def _generate_allure_report(self): #print("Allure Command Line Used: {cmd}".format(cmd=cmd)) allure_report = os.path.join(allure_report_dir,"index.html") CafyLog.htmlfile_link = allure_report + #TODO: Fix the htmlfile_link variable allure_html_report = os.path.join(_CafyConfig.allure_server,allure_report.strip("/")) self.allure_html_report = allure_html_report if CONTAINER_MODE: From d6bcb01c8696ddeccc9cd35f99a3c0b8d1a82064 Mon Sep 17 00:00:00 2001 From: shreyash Date: Tue, 16 May 2023 16:39:46 -0700 Subject: [PATCH 10/14] Email report attributes to have host paths instead of container paths --- cafy_pytest/plugin.py | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 9876045..61ffaef 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -377,7 +377,6 @@ def pytest_configure(config): _current_time = get_datentime() pid = os.getpid() work_dir_name = "%s_%s_p%s" % (script_name,_current_time, pid ) - if not config.option.reportdir: #If workdir option is set, execute the if block and if not given, #execute the else block where the workdir will be set to @@ -889,8 +888,6 @@ def _sendemail(self): def _generate_with_template(self, terminalreporter): '''generate report using template''' #additional field of hybrid_mode_status_dict for html template in order display mode of each testcase in email report - print (f"########CONTAINER_MODE = {CONTAINER_MODE}") - print (f"########self.host_archive = {self.host_archive}") if hasattr(CafyLog,"hybrid_mode_dict") and CafyLog.hybrid_mode_dict.get('mode',None): cafy_kwargs = {'terminalreporter': terminalreporter, 'testcase_dict': self.testcase_dict, @@ -1869,13 +1866,12 @@ def pytest_terminal_summary(self, terminalreporter): terminalreporter.write_line(self.tabulate_result) self.dump_model_coverage_report() if CONTAINER_MODE: - terminalreporter.write_line("Results: {work_dir}".format(work_dir=CafyLog.container_mode_work_dir)) - terminalreporter.write_line( - "Reports: {allure_html_report}".format(allure_html_report=self.host_allure_html_report)) + terminalreporter.write_line(f"Results: {CafyLog.container_mode_work_dir}") + #terminalreporter.write_line(f"Reports: {self.host_allure_html_report}") else: - terminalreporter.write_line("Results: {work_dir}".format(work_dir=CafyLog.work_dir)) - - terminalreporter.write_line("Reports: {allure_html_report}".format(allure_html_report=self.allure_html_report)) + terminalreporter.write_line(f"Results: {CafyLog.work_dir}") + #terminalreporter.write_line(f"Reports: {self.allure_html_report}") + terminalreporter.write_line(f"Reports: {self.allure_html_report}") self.collect_collection_report() self._generate_email_report(terminalreporter) @@ -1978,23 +1974,30 @@ def _generate_allure_report(self): allure_path=allure_path, allure_source_dir=allure_source_dir, allure_report_dir=allure_report_dir) - #print("Allure Command Line Used: {cmd}".format(cmd=cmd)) + os.system(cmd) allure_report = os.path.join(allure_report_dir,"index.html") - CafyLog.htmlfile_link = allure_report - #TODO: Fix the htmlfile_link variable allure_html_report = os.path.join(_CafyConfig.allure_server,allure_report.strip("/")) - self.allure_html_report = allure_html_report + """ if CONTAINER_MODE: host_allure_report_dir = os.path.join(self.host_archive,"reports") host_allure_report = os.path.join(host_allure_report_dir,"index.html") host_allure_html_report = os.path.join(_CafyConfig.allure_server,host_allure_report.strip("/")) self.host_allure_html_report = host_allure_html_report - os.system(cmd) - #print("Report Generated at: {allure_report}".format(allure_report=allure_report)) - if CONTAINER_MODE: - self.log.info("Report: {allure_html_report}".format(allure_html_report=host_allure_html_report)) + CafyLog.htmlfile_link = host_allure_report + self.log.info(f"Report: {host_allure_html_report}") else: - self.log.info("Report: {allure_html_report}".format(allure_html_report=allure_html_report)) + CafyLog.htmlfile_link = allure_report + self.log.info(f"Report: {allure_html_report}") + """ + if CONTAINER_MODE: + allure_report_dir = os.path.join(self.host_archive,"reports") + allure_report = os.path.join(allure_report_dir,"index.html") + allure_html_report = os.path.join(_CafyConfig.allure_server,allure_report.strip("/")) + + self.allure_html_report = allure_html_report + CafyLog.htmlfile_link = allure_report + self.log.info(f"Report: {allure_html_report}") + _CafyConfig.summary["allure2"] = { "commandline" : cmd, "html" : allure_html_report, @@ -2153,8 +2156,7 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc self.testbed = None self.registration_id = CafyLog.registration_id self.submitter = EmailReport.USER - self.cafy_repo = EmailReport.CAFY_REPO if not CONTAINER_MODE else CONTAINER_MODE_CAFY_REPO - #TODO: check on cafy_Repo variable value + self.cafy_repo = EmailReport.CAFY_REPO if not CONTAINER_MODE else os.environ.get("HOST_GIT_REPO", None) self.topo_file = topo_file #TODO: topo_file variable needs to print host path for CONTAINER mode self.run_dir = self.terminalreporter.startdir.strpath From dc0d29ac0704170d78472eae53cd5890bcfc5e0c Mon Sep 17 00:00:00 2001 From: shreyash Date: Wed, 17 May 2023 14:28:54 -0700 Subject: [PATCH 11/14] remove print cmd --- cafy_pytest/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 61ffaef..ff252b6 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -338,7 +338,6 @@ def _requests_retry(logger, url, method, data=None, files=None, headers=None, t @pytest.hookimpl(tryfirst=True) def pytest_configure(config): - print (f"config: {config}") config._environment = [] email_list = config.option.email_list email_from = config.option.email_from From f9ac306a91737332547a2b9834ff2d62fc4a8df1 Mon Sep 17 00:00:00 2001 From: shreyash Date: Wed, 17 May 2023 14:32:30 -0700 Subject: [PATCH 12/14] remove print cmd --- cafy_pytest/plugin.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index ff252b6..03b58c9 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -1866,10 +1866,8 @@ def pytest_terminal_summary(self, terminalreporter): self.dump_model_coverage_report() if CONTAINER_MODE: terminalreporter.write_line(f"Results: {CafyLog.container_mode_work_dir}") - #terminalreporter.write_line(f"Reports: {self.host_allure_html_report}") else: terminalreporter.write_line(f"Results: {CafyLog.work_dir}") - #terminalreporter.write_line(f"Reports: {self.allure_html_report}") terminalreporter.write_line(f"Reports: {self.allure_html_report}") self.collect_collection_report() @@ -1914,7 +1912,6 @@ def _parse_all_log(self, input_file_handler): pass else: if log_parsing_state is LogState.NONE: - # print("Starting generic log") log_grouping = GenericLogGrouping() all_log_groupings.append(log_grouping) log_parsing_state = LogState.GENERIC @@ -1976,18 +1973,6 @@ def _generate_allure_report(self): os.system(cmd) allure_report = os.path.join(allure_report_dir,"index.html") allure_html_report = os.path.join(_CafyConfig.allure_server,allure_report.strip("/")) - """ - if CONTAINER_MODE: - host_allure_report_dir = os.path.join(self.host_archive,"reports") - host_allure_report = os.path.join(host_allure_report_dir,"index.html") - host_allure_html_report = os.path.join(_CafyConfig.allure_server,host_allure_report.strip("/")) - self.host_allure_html_report = host_allure_html_report - CafyLog.htmlfile_link = host_allure_report - self.log.info(f"Report: {host_allure_html_report}") - else: - CafyLog.htmlfile_link = allure_report - self.log.info(f"Report: {allure_html_report}") - """ if CONTAINER_MODE: allure_report_dir = os.path.join(self.host_archive,"reports") allure_report = os.path.join(allure_report_dir,"index.html") @@ -2027,7 +2012,6 @@ def pytest_sessionfinish(self): headers = {'content-type': 'application/json'} try: url = 'http://{0}:5001/uploadcollectorlogfile/'.format(CafyLog.debug_server) - print("url = ", url) self.log.info("Calling registration upload collector logfile service (url:%s)" %url) response = _requests_retry(self.log, url, 'POST', json=params, headers=headers, timeout=300) if response is not None and response.status_code == 200: @@ -2215,10 +2199,6 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc else: print('\n Email html report not generated') - - - - if CafyLog.email_htmlfile_link: self.summary_report = CafyLog.email_htmlfile_link if CafyLog.web_host: From 293f5b0c22520db0ad13faefea97a4650218b890 Mon Sep 17 00:00:00 2001 From: shreyash Date: Wed, 17 May 2023 14:34:57 -0700 Subject: [PATCH 13/14] yaml.safeload instead of yaml.load() --- cafy_pytest/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index 03b58c9..af5725b 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -245,7 +245,7 @@ def is_valid_cafyarg(arg): #if block is executed when arg is not a file,instead it is string of dict if not os.path.exists(arg): eval(arg) - argdict = yaml.load(arg) + argdict = yaml.safe_load(arg) CafyLog.script_args = argdict else: #else block is executed when arg is a file @@ -263,7 +263,7 @@ def load_config_file(filename=None): _filename = os.path.join( git_repo, "work", "pytest_cafy_config.yaml") with open(_filename, 'r') as stream: - return (yaml.load(stream)) + return (yaml.safe_load(stream)) except: return {} From 2308c95bca3aad289dbbc768dc149aecd2453d54 Mon Sep 17 00:00:00 2001 From: shreyash Date: Tue, 29 Aug 2023 11:29:57 -0700 Subject: [PATCH 14/14] allure step banner --- cafy_pytest/cafy.py | 9 ++++++++- cafy_pytest/plugin.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cafy_pytest/cafy.py b/cafy_pytest/cafy.py index cd40408..94e23e0 100644 --- a/cafy_pytest/cafy.py +++ b/cafy_pytest/cafy.py @@ -5,6 +5,9 @@ from allure_commons._allure import StepContext as AllureStepContext import pytest from utils.cafyexception import CafyException +from logger.cafylog import CafyLog +log = CafyLog("cafy_pytest_step") + class Cafy: class Globals: @@ -45,8 +48,10 @@ def __init__(self, title, params, logger=None, blocking=True): super().__init__(title, params) self.blocking = blocking self.logger = logger + self.title=title def __enter__(self): + log.title(f" Start of step: {self.title}") super().__enter__() def __exit__(self, exc_type, exc_val, exc_tb): @@ -58,13 +63,15 @@ def __exit__(self, exc_type, exc_val, exc_tb): exc_type=exc_type, exc_tb=exc_tb)) Cafy.RunInfo.active_exceptions.append(exc_val) - + log.title(f" Finish of step: {self.title}") return not self.blocking class StepScope(): def __init__(self, title): self.title = title + #log.title(title) + def __enter__(self): Cafy.RunInfo.active_exceptions = list() diff --git a/cafy_pytest/plugin.py b/cafy_pytest/plugin.py index af5725b..4d5c61e 100644 --- a/cafy_pytest/plugin.py +++ b/cafy_pytest/plugin.py @@ -2103,6 +2103,8 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc option = self.terminalreporter.config.option self.script_list = option.file_or_dir # TODO check if CONTAINER_MODE and then set the above script_list variable accordingly + if CONTAINER_MODE: + pass self.title = ' '.join(self.script_list) self.image = os.getenv("IMAGE", "Unknown") if os.environ.get("BUILD_URL"):