Fixed xfail report and changed results posting

This commit is contained in:
Yevheniia Berdnyk 2022-07-21 07:07:38 +03:00
parent 8a29830625
commit 46e5def13d
No known key found for this signature in database
GPG Key ID: 0642C73C66214825
3 changed files with 38 additions and 24 deletions

View File

@ -81,19 +81,29 @@ class GithubHtmlReport(BaseTestReport):
tr_case_ids=','.join([str(test.testrail_case_id) for test in tests]))
if not not_executed_tests:
groups = {i: list() for i in set([test.group_name for test in tests])}
for i in tests:
groups[i.group_name].append(i)
html += "<br/>"
html += "<table style=\"width: 100%\">"
html += "<colgroup>"
html += "<col span=\"1\" style=\"width: 20%;\">"
html += "<col span=\"1\" style=\"width: 80%;\">"
html += "</colgroup>"
html += "<tbody>"
html += "<tr>"
html += "</tr>"
for i, test in enumerate(tests):
html += self.build_test_row_html(i, test, run_id)
html += "</tbody>"
html += "</table>"
for class_name, tests_list in groups.items():
if class_name:
html += "<h4>Class %s:</h4>" % class_name
else:
html += "<h4>Single device tests:</h4>"
html += "<table style=\"width: 100%\">"
html += "<colgroup>"
html += "<col span=\"1\" style=\"width: 20%;\">"
html += "<col span=\"1\" style=\"width: 80%;\">"
html += "</colgroup>"
html += "<tbody>"
html += "<tr>"
html += "</tr>"
for i, test in enumerate(tests_list):
html += self.build_test_row_html(i, test, run_id)
html += "</tbody>"
html += "</table>"
html += "</details>"
return html

View File

@ -245,17 +245,19 @@ class TestrailReport(BaseTestReport):
description_title += "Not executed tests: %d\n" % len(not_executed_tests)
description_title += "\n"
ids_failed_test = []
description, case_info = '', ''
single_devices_block, group_blocks, case_info = str(), dict(), str()
if failed_tests:
for i, test in enumerate(failed_tests):
for test in failed_tests:
if test.group_name:
group_blocks[test.group_name] = "-------\n## Class: %s:\n" % test.group_name
for test in failed_tests:
last_testrun = test.testruns[-1]
test_rail_link = self.get_test_result_link(self.run_id, test.testrail_case_id)
ids_failed_test.append(test.testrail_case_id)
case_title = '\n'
case_title += '-------\n'
case_title += "## %s) ID %s: [%s](%s) \n" % (
i + 1, test.testrail_case_id, test.name, test_rail_link)
full_error = last_testrun.error[:255]
case_title += "## ID %s: [%s](%s) \n" % (test.testrail_case_id, test.name, test_rail_link)
full_error = last_testrun.error[-255:]
(code_error, no_code_error_str, issue_id) = self.separate_xfail_error(full_error)
if issue_id:
test_rail_xfail = self.make_error_with_gh_issue_link(no_code_error_str, issue_id)
@ -272,14 +274,13 @@ class TestrailReport(BaseTestReport):
% (f, job_url, self.get_sauce_final_screenshot_url(job_id))
if test.group_name:
class_name = "Class: %s\n" % test.group_name
description += case_title + class_name + error + case_info
group_blocks[test.group_name] += case_title + error + case_info
else:
description += case_title + error + case_info
description_title += '## Failed tests: %s \n' % ','.join(map(str, ids_failed_test))
single_devices_block += case_title + error + case_info
description_title += '## Failed tests: %s \n' % ','.join(map(str, ids_failed_test))
if not_executed_tests:
description_title += "## Not executed tests: %s\n" % ','.join([str(i) for i in not_executed_tests])
final_description = description_title + description
final_description = description_title + single_devices_block + ''.join([i for i in group_blocks.values()])
request_body = {'description': final_description}
return self.post('update_run/%s' % self.run_id, request_body)

View File

@ -238,7 +238,8 @@ def pytest_runtest_makereport(item, call):
is_group = "xdist_group" in item.keywords._markers or "xdist_group" in item.parent.keywords._markers
error_intro, error = 'Test setup failed:', ''
final_error = '%s %s' % (error_intro, error)
if hasattr(report, 'wasxfail'):
if hasattr(report, 'wasxfail') and str([mark.args[0] for mark in item.iter_markers(name='testrail_id')][0]) \
in str(item.config.getoption("run_testrail_ids")):
if '[NOTRUN]' in report.wasxfail:
test_suite_data.set_current_test(item.name, testrail_case_id=get_testrail_case_id(item))
test_suite_data.current_test.create_new_testrun()
@ -269,7 +270,9 @@ def pytest_runtest_makereport(item, call):
error = catch_error()
if report.failed:
current_test.testruns[-1].error = error
if hasattr(report, 'wasxfail'):
in_run = str([mark.args[0] for mark in item.iter_markers(name='testrail_id')][0]) in str(item.config.getoption(
"run_testrail_ids"))
if hasattr(report, 'wasxfail') and in_run:
current_test.testruns[-1].xfail = report.wasxfail
if error:
current_test.testruns[-1].error = '%s [[%s]]' % (error, report.wasxfail)