From c347b2ce4700f014b237591ea33d7bdcf37ef899 Mon Sep 17 00:00:00 2001 From: Varun Krishnan Date: Mon, 18 Mar 2019 10:23:42 -0400 Subject: [PATCH 01/18] created plugin changes to change test_case status if there is a crash or a traceback --- pytest_cafy/plugin.py | 44 +++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index 74ff9c3..bcf3058 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -21,11 +21,12 @@ import pytest from _pytest.terminal import TerminalReporter -from _pytest.runner import runtestprotocol +from _pytest.runner import runtestprotocol, TestReport from _pytest.mark import MarkInfo from enum import Enum from tabulate import tabulate +from pprint import pprint, pformat from shutil import copyfile from configparser import ConfigParser from datetime import datetime @@ -813,7 +814,7 @@ def pytest_runtest_teardown(self, item, nextitem): self.log.set_testcase("Teardown") else: testcase_name = self.get_test_name(nextitem.nodeid) - self.log.set_testcase(testcase_name) + # self.log.set_testcase(testcase_name) testcase_name = self.get_test_name(item.nodeid) self.log.info('Teardown module for testcase {}'.format(testcase_name)) @@ -905,14 +906,6 @@ def pytest_runtest_logreport(self, report): if report.when == 'teardown': - if self.reg_dict: - reg_id = self.reg_dict.get('reg_id') - test_class = report.nodeid.split('::')[1] - if (test_class not in self.analyzer_testcase.keys()) or self.analyzer_testcase.get(test_class) == 1: - analyzer_status = self.post_testcase_status(reg_id, testcase_name, CafyLog.debug_server) - self.log.info('Analyzer Status is {}'.format(analyzer_status)) - else: - self.log.info('Analyzer is not invoked as testcase failed in setup') status = "unknown" if testcase_name in self.testcase_dict: status = self.testcase_dict[testcase_name] @@ -1034,6 +1027,37 @@ def pytest_runtest_logreport(self, report): else: self.testcase_failtrace_dict[testcase_name] = None + @pytest.hookimpl(hookwrapper=True, trylast=True) + def pytest_runtest_makereport(self, item, call): + print("in cafy plugin makereport") + outcome = (yield) + if call.when =='call': + report = outcome.get_result() + testcase_name = self.get_test_name(report.nodeid) + if self.reg_dict: + reg_id = self.reg_dict.get('reg_id') + test_class = report.nodeid.split('::')[1] + if (test_class not in self.analyzer_testcase.keys()) or self.analyzer_testcase.get(test_class) == 1: + analyzer_status = self.post_testcase_status(reg_id, testcase_name, CafyLog.debug_server) + self.log.info('Analyzer Status is {}'.format(analyzer_status)) + else: + self.log.info('Analyzer is not invoked as testcase failed in setup') + failures = json.loads(analyzer_status['failures']) + if len(failures): + self.log.error('Test case failed due to crash/traceback {}'.format(pformat(failures))) + test_outcome = 'failed' + report = TestReport( + report.nodeid, + report.location, + report.keywords, + test_outcome, + report.longrepr, + report.when, + report.sections, + report.duration, + ) + outcome.force_result(report) + def check_call_report(self, item, nextitem): """ From d3a5529f9d85db479a823d11cce07f7e2aea711b Mon Sep 17 00:00:00 2001 From: Varun Krishnan Date: Mon, 1 Apr 2019 14:27:10 -0400 Subject: [PATCH 02/18] removed extraneous print statements --- pytest_cafy/plugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index bcf3058..f34a6ef 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1029,7 +1029,6 @@ def pytest_runtest_logreport(self, report): @pytest.hookimpl(hookwrapper=True, trylast=True) def pytest_runtest_makereport(self, item, call): - print("in cafy plugin makereport") outcome = (yield) if call.when =='call': report = outcome.get_result() From 77d141e24c6ba5f3d8ba6b4a87e83236fa1404b4 Mon Sep 17 00:00:00 2001 From: Varun Krishnan Date: Tue, 2 Apr 2019 13:37:45 -0400 Subject: [PATCH 03/18] ensuring backward compatibility --- pytest_cafy/plugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index f34a6ef..e115303 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1041,7 +1041,9 @@ def pytest_runtest_makereport(self, item, call): self.log.info('Analyzer Status is {}'.format(analyzer_status)) else: self.log.info('Analyzer is not invoked as testcase failed in setup') - failures = json.loads(analyzer_status['failures']) + if isinstance(analyzer_status, bool): + return + failures = json.loads(analyzer_status.get('failures',[])) if len(failures): self.log.error('Test case failed due to crash/traceback {}'.format(pformat(failures))) test_outcome = 'failed' From 1533fdc5284a8aaebd1d2be11dddf3a65c7d0a4a Mon Sep 17 00:00:00 2001 From: Varun Krishnan Date: Mon, 22 Apr 2019 17:30:11 -0400 Subject: [PATCH 04/18] changes to add verbose logs to the work directory --- pytest_cafy/plugin.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index 74ff9c3..16dc1d9 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1438,12 +1438,19 @@ def pytest_sessionfinish(self): response = requests.post(url, json=params, headers=headers) if response is not None and response.status_code == 200: if response.text: + summary_log = response.text + if '+'*120 in response.text: + summary_log, verbose_log = response.text.split('+'*120) self.log.info ("Debug Collector logs: %s" %(response.text)) if 'Content-Disposition' in response.headers: debug_collector_log_filename = response.headers['Content-Disposition'].split('filename=')[-1] collector_log_file_full_path = os.path.join(CafyLog.work_dir,debug_collector_log_filename) with open(collector_log_file_full_path, 'w') as f: - f.write(response.text) + f.write(summary_log) + verbose_log_file_path = collector_log_file_full_path.replace("debug_collection.log", + "verbose_collection.log") + with open(verbose_log_file_path, 'w') as f: + f.write(verbose_log) try: DebugLibrary.convert_collector_logs_to_json(collector_log_file_full_path) except: From 3a23bce13da0166e2bac6552607da71383016c99 Mon Sep 17 00:00:00 2001 From: Neeba Chandy Date: Wed, 22 May 2019 09:47:17 -0700 Subject: [PATCH 05/18] Fix for live logging error when the test failed in setup --- pytest_cafy/plugin.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index e115303..baf7136 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1027,6 +1027,15 @@ def pytest_runtest_logreport(self, report): else: self.testcase_failtrace_dict[testcase_name] = None + # Add the testcase status to testcase_dict as error if the test failed in setup + try: + if report.when == 'setup' and report.outcome == 'failed': + testcase_name = self.get_test_name(report.nodeid) + self.testcase_dict[testcase_name] = 'error' + except Exception as e: + self.log.error("Error getting the testcase status for setup failure: {}".format(e)) + + @pytest.hookimpl(hookwrapper=True, trylast=True) def pytest_runtest_makereport(self, item, call): outcome = (yield) From 28d80959d4e5bb5f8173d34c7a4f930b984b8112 Mon Sep 17 00:00:00 2001 From: Neeba Chandy Date: Fri, 24 May 2019 10:50:52 -0700 Subject: [PATCH 06/18] Add timeout for live logging api calls --- pytest_cafy/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index baf7136..3087b2a 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -535,7 +535,7 @@ def pytest_collection_modifyitems(session, config, items): log.info("url: {}".format(url)) log.info("Calling API service for live logging of reg_id ") params = {"reg_id": CafyLog.registration_id} - response = requests.patch(url, json=params, headers=headers) + response = requests.patch(url, json=params, headers=headers, timeout=120) if response.status_code == 200: log.info("Calling API service for live logging of reg_id successful") else: @@ -559,7 +559,7 @@ def pytest_collection_modifyitems(session, config, items): url = '{0}/api/runs/{1}/cases'.format(os.environ.get('CAFY_API_HOST'), os.environ.get('CAFY_RUN_ID')) log.info("url: {}".format(url)) log.info("Calling API service for live logging of collected testcases ") - response = requests.post(url, json=CafyLog.collected_testcases, headers=headers) + response = requests.post(url, json=CafyLog.collected_testcases, headers=headers, timeout=120) if response.status_code == 200: log.info("Calling API service for live logging of collected testcases successful") else: From 537046fbc1331e047ea813de3c0eb6fab64a4d73 Mon Sep 17 00:00:00 2001 From: Anand Jayaram Date: Mon, 27 May 2019 01:36:58 -0700 Subject: [PATCH 07/18] Add timeout of 5s to get git commit id --- pytest_cafy/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index baf7136..c0d5e07 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1579,7 +1579,7 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc self.topo_file = topo_file self.run_dir = self.terminalreporter.startdir.strpath try: - self.git_commit_id = subprocess.check_output(['git', 'rev-parse', 'origin/master']).decode("utf-8").replace('\n', '') + 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 From 12c6416480b9e0e63f406a4c501925b49e8312ca Mon Sep 17 00:00:00 2001 From: Anand Jayaram Date: Mon, 27 May 2019 01:49:26 -0700 Subject: [PATCH 08/18] Redo email report --- pytest_cafy/resources/mail_template.html | 310 +++++++++++------------ 1 file changed, 154 insertions(+), 156 deletions(-) diff --git a/pytest_cafy/resources/mail_template.html b/pytest_cafy/resources/mail_template.html index 65ba9f0..d596794 100644 --- a/pytest_cafy/resources/mail_template.html +++ b/pytest_cafy/resources/mail_template.html @@ -4,7 +4,7 @@

Detailed Results

-  🕐 {{report.run_time}}   +  🕐 {{report.run_time}}   @@ -24,24 +24,41 @@

Detailed Results

{% macro detailed_data(report) -%} {% for name, status in report.testcase_dict.items() %} - - {{name}} - {{status}} - {{report.testcase_failtrace_dict[name]}} - + + + {{name}} + + + {{status}} + + + {{report.testcase_failtrace_dict[name]}} + + {% endfor %} {%- endmacro %} - {% macro summary(report) -%} -
{{report.passed}}
-
{{report.xpassed}}
-
{{report.failed}}
-
{{report.skipped}}
-
{{report.xfailed}}
-
{{report.total}}
+ +
{{report.passed}}
+ + +
{{report.xpassed}}
+ + +
{{report.failed}}
+ + +
{{report.skipped}}
+ + +
{{report.xfailed}}
+ + +
{{report.total}}
+ {%- endmacro %} @@ -50,171 +67,152 @@

Detailed Results

{{report.title}} - + -
+

{{report.script_list}}


- - -

Run Info

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {% if report.debug_dirs %} - - - - {% endif %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestBed{{report.testbed}}
Registration ID{{report.registration_id}}
Submitter{{report.submitter}}
Run directory{{report.run_dir}}
Git commit id{{report.git_commit_id}}
Script list{{report.script_list}}
Start time{{report.start_time}}
Stop time{{report.stop_time}}
Run time{{report.run_time}}
Debug directories -
    - {% for debug_dir in report.debug_dirs %} -
  • {{debug_dir}}
  • - {% endfor %} -
-
Cafy repo{{report.cafy_repo}}
Exec host{{report.exec_host}}
Python version{{report.python_version}}
Exec platform{{report.platform}}
Topology file{{report.topo_file}}
Archive{{report.archive}}
Allure report link{{report.htmlprefix}}{{report.allure_report}}
-

Summary

- + - - - - - - + + + + + + - - + + {{ summary(report) }} - +
Passed
Xpassed
Failed
Skipped
Xfailed
Total
+
Passed
+
+
Xpassed
+
+
Failed
+
+
Skipped
+
+
Xfailed
+
+
Total
+
+ - -

Testcase Status Summary

+

Run Info

- + + + {% if report.testbed %} - - - + + - - - {{ detailed_data(report) }} - + {% endif %} + {% if report.registration_id %} + + + + + {% endif %} + + + + + + + + + {% if report.git_commit_id %} + + + + + {% endif %} + + + + + + + + + + + + + + + + + {% if report.debug_dirs %} + + + + {% endif %} + + + + + + + + + + + + + + + + + + + + + +
Testcase NameResultFail LogTestBed{{report.testbed}}
Registration ID{{report.registration_id}}
Submitter{{report.submitter}}
Run directory{{report.run_dir}}
Git commit id{{report.git_commit_id}}
Script list{{report.script_list}}
Start time{{report.start_time}}
Stop time{{report.stop_time}}
Run time{{report.run_time}}
Debug directories +
    + {% for debug_dir in report.debug_dirs %} +
  • {{debug_dir}}
  • + {% endfor %} +
+
Cafy repo{{report.cafy_repo}}
Exec host{{report.exec_host}}
Topology file{{report.topo_file}}
Archive{{report.archive}}
Allure report link + {{report.htmlprefix}}{{report.allure_report}} +
- -

Build Info

-

- Image -  {{report.image}}

+ +

Testcase Status Summary

- + + + + + + + - - - - - - - - - - - - - - - - - {% if report.jenkins_url %} - - - - - {% endif %} + {{ detailed_data(report) }}
+ Testcase Name + + Result + + Fail Log +
XR EFR{{report.xr_efr}}
XR workspace{{report.xr_ws}}
Calvados EFR{{report.cal_efr}}
Calvados workspace{{report.cal_ws}}
Jenkins URL{{report.jenkins_url}}
- - - - {{ detailed_header(report) }} - +
From 146de419f5e562a00df1e89b10cc4b3122801176 Mon Sep 17 00:00:00 2001 From: Anand Jayaram Date: Thu, 30 May 2019 18:26:56 -0700 Subject: [PATCH 09/18] Added shorthand for test-input-file and report-dir --- pytest_cafy/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index d23ab96..039c052 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -123,7 +123,7 @@ def pytest_addoption(parser): group.addoption('--work-dir', dest="workdir", metavar="DIR", default=None, help="Path for work dir") - group.addoption('--report-dir', dest="reportdir", + group.addoption('-R','--report-dir', dest="reportdir", metavar="DIR", default=None, help="Path for report dir") @@ -134,7 +134,7 @@ def pytest_addoption(parser): type=lambda x: is_valid_param(x, file_type='topology_file'), help='Filename of your testbed') - group.addoption('--test-input-file', action='store', dest='test_input_file', + group.addoption('-I', '--test-input-file', action='store', dest='test_input_file', metavar='test_input_file', type=lambda x: is_valid_param(x, file_type='input_file'), help='Filename of your test input file') From ed454e2c5d43b80da40c640af55cd7e2b6b705b4 Mon Sep 17 00:00:00 2001 From: Anand Jayaram Date: Thu, 30 May 2019 18:36:53 -0700 Subject: [PATCH 10/18] Get the cafykit release for email report --- pytest_cafy/plugin.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index d23ab96..f8cc0b4 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1571,7 +1571,11 @@ def __init__(self, terminalreporter, testcase_dict, testcase_failtrace_dict, arc # Run Info self.exec_host = platform.node() self.python_version = platform.python_version() - self. platform = platform.platform() + self.platform = platform.platform() + try: + self.cafykit_release = os.path.basename(os.environ.get("VIRTUAL_ENV")) + except: + self.cafykit_release = None self.testbed = None self.registration_id = CafyLog.registration_id self.submitter = EmailReport.USER From 963ec702d8c2691689d383bb963784abb66e8b12 Mon Sep 17 00:00:00 2001 From: Anand Jayaram Date: Thu, 30 May 2019 18:39:28 -0700 Subject: [PATCH 11/18] update css to add cafykit release if present --- pytest_cafy/resources/mail_template.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pytest_cafy/resources/mail_template.html b/pytest_cafy/resources/mail_template.html index d596794..f1929a3 100644 --- a/pytest_cafy/resources/mail_template.html +++ b/pytest_cafy/resources/mail_template.html @@ -139,6 +139,12 @@

Run Info

{{report.git_commit_id}} {% endif %} + {% if report.cafykit_release %} + + Cafykit Release + {{report.cafykit_release}} + + {% endif %} Script list {{report.script_list}} From 1cf43ff8ac96eef01a046115f7dba29183267e7a Mon Sep 17 00:00:00 2001 From: Anand Jayaram Date: Tue, 4 Jun 2019 22:57:23 -0700 Subject: [PATCH 12/18] reverting some breakages from PR #31 --- pytest_cafy/resources/mail_template.html | 290 +++++++++-------------- 1 file changed, 108 insertions(+), 182 deletions(-) diff --git a/pytest_cafy/resources/mail_template.html b/pytest_cafy/resources/mail_template.html index f1929a3..3b33b97 100644 --- a/pytest_cafy/resources/mail_template.html +++ b/pytest_cafy/resources/mail_template.html @@ -1,64 +1,14 @@ -{% macro detailed_header(report) -%} - -

Detailed Results

-

-  🕐 {{report.run_time}}   - - - View allure report > - - - - View Summary report > - -

- -{%- endmacro %} - - -{% macro detailed_data(report) -%} -{% for name, status in report.testcase_dict.items() %} - - - {{name}} - - - {{status}} - - - {{report.testcase_failtrace_dict[name]}} - - -{% endfor %} -{%- endmacro %} - {% macro summary(report) -%} - -
{{report.passed}}
- - -
{{report.xpassed}}
- - -
{{report.failed}}
- - -
{{report.skipped}}
- - -
{{report.xfailed}}
- - -
{{report.total}}
- +
{{report.passed}}
+
{{report.xpassed}}
+
{{report.failed}}
+
{{report.skipped}}
+
{{report.xfailed}}
+
{{report.total}}
{%- endmacro %} @@ -67,158 +17,134 @@

Detailed Results

{{report.title}} - + -
+

{{report.script_list}}


Summary

- + - - - - - - + + + + + + - - + + {{ summary(report) }} - +
-
Passed
-
-
Xpassed
-
-
Failed
-
-
Skipped
-
-
Xfailed
-
-
Total
-
Passed
Xpassed
Failed
Skipped
Xfailed
Total
- + +

Run Info

- - - {% if report.testbed %} - - - - - {% endif %} - {% if report.registration_id %} - - - - - {% endif %} - - - - - - - - - {% if report.git_commit_id %} - - - - - {% endif %} - {% if report.cafykit_release %} - - - - - {% endif %} - - - - - - - - - - - - - - - - - {% if report.debug_dirs %} - - - - {% endif %} - - + + + + + + + {% if report.registration_id %} + + + + + {% endif %} + + + + + + + + + {% if report.git_commit_id %} + + + + + {% endif %} + {% if report.cafykit_release %} + + + + + {% endif %} + + + + + + + + + + + + + + + + + {% if report.debug_dirs %} + + + + {% endif %} + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
TestBed{{report.testbed}}
Registration ID{{report.registration_id}}
Submitter{{report.submitter}}
Run directory{{report.run_dir}}
Git commit id{{report.git_commit_id}}
Cafykit Release{{report.cafykit_release}}
Script list{{report.script_list}}
Start time{{report.start_time}}
Stop time{{report.stop_time}}
Run time{{report.run_time}}
Debug directories -
    - {% for debug_dir in report.debug_dirs %} -
  • {{debug_dir}}
  • - {% endfor %} -
-
TestBed{{report.testbed}}
Registration ID{{report.registration_id}}
Submitter{{report.submitter}}
Run directory{{report.run_dir}}
Git commit id{{report.git_commit_id}}
Cafykit Release{{report.cafykit_release}}
Script list{{report.script_list}}
Start time{{report.start_time}}
Stop time{{report.stop_time}}
Run time{{report.run_time}}
Debug directories +
    + {% for debug_dir in report.debug_dirs %} +
  • {{debug_dir}}
  • + {% endfor %} +
+
Cafy repo {{report.cafy_repo}}
Exec host{{report.exec_host}}
Topology file{{report.topo_file}}
Archive{{report.archive}}
Allure report link - {{report.htmlprefix}}{{report.allure_report}} -
Exec host{{report.exec_host}}
Topology file{{report.topo_file}}
Archive{{report.archive}}
Allure report link{{report.htmlprefix}}{{report.allure_report}}

Testcase Status Summary

- + - - - + + + - - + + {{ detailed_data(report) }} - +
- Testcase Name - - Result - - Fail Log - Testcase NameResultFail Log
-
+ + From 259ba0cfb608316bdce81bf201e557e6df3c2639 Mon Sep 17 00:00:00 2001 From: Varun Krishnan Date: Thu, 6 Jun 2019 10:34:53 -0400 Subject: [PATCH 13/18] printing only summary logs --- pytest_cafy/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index 16dc1d9..5be7acd 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1441,7 +1441,7 @@ def pytest_sessionfinish(self): summary_log = response.text if '+'*120 in response.text: summary_log, verbose_log = response.text.split('+'*120) - self.log.info ("Debug Collector logs: %s" %(response.text)) + self.log.info ("Debug Collector logs: %s" %(summary_log)) if 'Content-Disposition' in response.headers: debug_collector_log_filename = response.headers['Content-Disposition'].split('filename=')[-1] collector_log_file_full_path = os.path.join(CafyLog.work_dir,debug_collector_log_filename) From 9c668a97421fe07846e8dae4860f815170835f2a Mon Sep 17 00:00:00 2001 From: Anand Jayaram Date: Thu, 6 Jun 2019 09:39:25 -0700 Subject: [PATCH 14/18] Fix to breakge in 19.23.12 release --- pytest_cafy/resources/mail_template.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pytest_cafy/resources/mail_template.html b/pytest_cafy/resources/mail_template.html index 3b33b97..7d2bb62 100644 --- a/pytest_cafy/resources/mail_template.html +++ b/pytest_cafy/resources/mail_template.html @@ -12,6 +12,15 @@ {%- endmacro %} +{% macro detailed_data(report) -%} +{% for name, status in report.testcase_dict.items() %} + + {{name}} + {{status}} + {{report.testcase_failtrace_dict[name]}} + +{% endfor %} +{%- endmacro %} From 0202eb91396c6b733b1974740ec719e75f415944 Mon Sep 17 00:00:00 2001 From: Amrendra Kumar Date: Wed, 19 Jun 2019 21:49:58 -0700 Subject: [PATCH 15/18] Safe Email Move terminal status before email. --- pytest_cafy/plugin.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index 03a4af5..9874161 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1364,13 +1364,17 @@ def pytest_terminal_summary(self, terminalreporter): if junitxml_file_path != _junitxml_filename: copyfile(_junitxml_filename, junitxml_file_path) os.chmod(junitxml_file_path, 0o775) + + temp_list = [] + terminalreporter.write_line("\n TestCase Summary Status Table") + for k,v in self.testcase_dict.items(): + temp_list.append((k,v)) + print (tabulate(temp_list, headers=['Testcase_name', 'Status'], tablefmt='grid')) if not self.no_email: - self._sendemail() - terminalreporter.write_line("\n TestCase Summary Status Table") - temp_list = [] - for k,v in self.testcase_dict.items(): - temp_list.append((k,v)) - print (tabulate(temp_list, headers=['Testcase_name', 'Status'], tablefmt='grid')) + try: + self._sendemail() + except Exception as err: + log.error("Error when sending email: {err}".format(err=str(error))) #Unset environ variables cafykit_mongo_learn & cafykit_mongo_read if set From 1b878532c79d60b958ea0e1bde920a3443eabee5 Mon Sep 17 00:00:00 2001 From: Amrendra Kumar Date: Wed, 19 Jun 2019 22:02:52 -0700 Subject: [PATCH 16/18] Minor fix --- pytest_cafy/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index 9874161..26e9400 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -1374,7 +1374,7 @@ def pytest_terminal_summary(self, terminalreporter): try: self._sendemail() except Exception as err: - log.error("Error when sending email: {err}".format(err=str(error))) + self.log.error("Error when sending email: {err}".format(err=str(err))) #Unset environ variables cafykit_mongo_learn & cafykit_mongo_read if set From c8ca5870bd4210521f7f788cedd53d58d20e0e09 Mon Sep 17 00:00:00 2001 From: Varun Krishnan Date: Wed, 17 Jul 2019 16:02:09 -0400 Subject: [PATCH 17/18] added timeout to all debug calls --- pytest_cafy/plugin.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pytest_cafy/plugin.py b/pytest_cafy/plugin.py index 26e9400..3031253 100755 --- a/pytest_cafy/plugin.py +++ b/pytest_cafy/plugin.py @@ -790,7 +790,7 @@ def initiate_analyzer(self, reg_id, test_case, debug_server): try: url = "http://{0}:5001/initiate_analyzer/".format(CafyLog.debug_server) self.log.info("Calling registration service (url:%s) to initialize analyzer" % url) - response = requests.post(url, data=params) + response = requests.post(url, data=params, timeout=300) if response.status_code == 200: self.log.info("Analyzer initialized") return True @@ -864,7 +864,7 @@ def check_analyzer_status(self, params, headers): try: url = "http://{0}:5001/end_test_case/".format(CafyLog.debug_server) self.log.info("Calling registration service (url:%s) to check analyzer status" % url) - response = requests.get(url, data=params) + response = requests.get(url, data=params, timeout=60) if response.status_code == 200: return response.json()['analyzer_status'] else: @@ -895,7 +895,7 @@ def pytest_runtest_logreport(self, report): try: url = 'http://{0}:5001/registertest/'.format(CafyLog.debug_server) self.log.info("Calling registration service to start handshake(url:%s" % url) - response = requests.post(url, json=params, headers=headers) + response = requests.post(url, json=params, headers=headers, timeout=300) if response.status_code == 200: self.log.info("Handshake part of registration service was successful") else: @@ -1318,7 +1318,7 @@ def invoke_reg_on_failed_testcase(self, params, headers): try: url = "http://{0}:5001/startdebug/".format(CafyLog.debug_server) self.log.info("Calling registration service (url:%s) to start collecting" % url) - response = requests.post(url, json=params, headers=headers) + response = requests.post(url, json=params, headers=headers, timeout=1500) if response.status_code == 200: return response else: @@ -1335,7 +1335,7 @@ def invoke_rc_on_failed_testcase(self, params, headers): try: url = "http://{0}:5003/startrootcause/".format(CafyLog.debug_server) self.log.info("Calling RC engine to start rootcause (url:%s)" % url) - response = requests.post(url, json=params, headers=headers) + response = requests.post(url, json=params, headers=headers, timeout=300) if response.status_code == 200: return response else: @@ -1441,7 +1441,7 @@ def _get_analyzer_log(self): "debug_server_name": CafyLog.debug_server} url = 'http://{0}:5001/get_analyzer_log/'.format(CafyLog.debug_server) try: - response = requests.get(url, data=params) + response = requests.get(url, data=params, timeout=300) if response is not None and response.status_code == 200: if response.text: if 'Content-Disposition' in response.headers: @@ -1473,7 +1473,7 @@ def pytest_sessionfinish(self): 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.post(url, json=params, headers=headers) + response = requests.post(url, json=params, headers=headers, timeout=300) if response is not None and response.status_code == 200: if response.text: summary_log = response.text @@ -1498,7 +1498,7 @@ def pytest_sessionfinish(self): url = 'http://{0}:5001/deleteuploadedfiles/'.format(CafyLog.debug_server) self.log.info("Calling registration delete upload file service (url:%s)" % url) - response = requests.post(url, json=params, headers=headers) + response = requests.post(url, json=params, headers=headers, timeout=300) if response.status_code == 200: self.log.info("Topology and input files deleted from registration server") else: From 6958e3a6a9d6f8ed2e840e78a1c4375cecce8836 Mon Sep 17 00:00:00 2001 From: shreyash Date: Mon, 29 Jul 2019 16:48:07 -0700 Subject: [PATCH 18/18] Create cafyrun alias to run pytest scripts JIRA issue CAFY-260 --- bin/cafyrun | 21 +++++++++++++++++++++ setup.py | 1 + 2 files changed, 22 insertions(+) create mode 100644 bin/cafyrun diff --git a/bin/cafyrun b/bin/cafyrun new file mode 100644 index 0000000..458d293 --- /dev/null +++ b/bin/cafyrun @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +import pytest +import _pytest.main +import sys + +# Customize messages for pytest exit codes +msg = {_pytest.main.EXIT_OK: 'OK', + _pytest.main.EXIT_TESTSFAILED: 'Tests failed', + _pytest.main.EXIT_INTERRUPTED: 'Interrupted', + _pytest.main.EXIT_INTERNALERROR: 'Internal error', + _pytest.main.EXIT_USAGEERROR: 'Usage error', + _pytest.main.EXIT_NOTESTSCOLLECTED: 'No tests collected'} + +exitcode = pytest.main(sys.argv[1:]) + + + + +print(msg[exitcode]) +sys.exit(exitcode) + diff --git a/setup.py b/setup.py index 38c2c93..aaa958b 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ url='https://github.com/kuamrend/cafy-pytest', description='Pytest Cafy Plugin', install_requires=['pytest>=2.3', 'jinja2'], + scripts=['bin/cafyrun'], # the following makes a plugin available to pytest entry_points={ 'pytest11': ['pytest_cafy = pytest_cafy.plugin']