e2e: requests.log for failed tests
This commit is contained in:
parent
a1662752bc
commit
69664322b8
|
@ -28,29 +28,31 @@ class BaseTestReport:
|
|||
file_name = "%s.json" % test_name
|
||||
return os.path.join(self.TEST_REPORT_DIR, file_name)
|
||||
|
||||
def save_geth(self, geth: dict):
|
||||
geth_paths = {}
|
||||
for log in geth.keys():
|
||||
geth_path = os.path.join(self.TEST_REPORT_DIR, log)
|
||||
result = open(geth_path, 'wb')
|
||||
result.write(geth[log])
|
||||
def save_logs(self, logs: dict):
|
||||
logs_paths = {}
|
||||
for log in logs.keys():
|
||||
log_path = os.path.join(self.TEST_REPORT_DIR, log)
|
||||
result = open(log_path, 'wb')
|
||||
result.write(logs[log])
|
||||
result.close()
|
||||
geth_paths[log] = geth_path
|
||||
return geth_paths
|
||||
logs_paths[log] = log_path
|
||||
return logs_paths
|
||||
|
||||
def save_test(self, test, geth: dict = None):
|
||||
if geth:
|
||||
geth_paths = self.save_geth(geth)
|
||||
def save_test(self, test, geth: dict = None, requests_log: dict = None):
|
||||
for log in geth, requests_log:
|
||||
if log:
|
||||
logs_paths = self.save_logs(log)
|
||||
else:
|
||||
if hasattr(test, 'geth_paths'):
|
||||
geth_paths = test.geth_paths
|
||||
if hasattr(test, 'logs_paths'):
|
||||
logs_paths = test.logs_paths
|
||||
else:
|
||||
geth_paths = ''
|
||||
logs_paths = ''
|
||||
|
||||
file_path = self.get_test_report_file_path(test.name)
|
||||
test_dict = {
|
||||
'testrail_case_id': test.testrail_case_id,
|
||||
'name': test.name,
|
||||
'geth_paths': geth_paths,
|
||||
'logs_paths': logs_paths,
|
||||
'testruns': list(),
|
||||
'group_name': test.group_name,
|
||||
'secured': test.secured
|
||||
|
@ -74,7 +76,7 @@ class BaseTestReport:
|
|||
first_commands=testrun_data['first_commands'],
|
||||
xfail=testrun_data['xfail']))
|
||||
tests.append(SingleTestData(name=test_data['name'],
|
||||
geth_paths=test_data['geth_paths'],
|
||||
logs_paths=test_data['logs_paths'],
|
||||
testruns=testruns,
|
||||
testrail_case_id=test_data['testrail_case_id'],
|
||||
grop_name=test_data['group_name'],
|
||||
|
|
|
@ -2,11 +2,11 @@ from typing import Dict
|
|||
|
||||
|
||||
class SingleTestData(object):
|
||||
def __init__(self, name, testruns, testrail_case_id, geth_paths, grop_name, secured):
|
||||
def __init__(self, name, testruns, testrail_case_id, logs_paths, grop_name, secured):
|
||||
self.testrail_case_id = testrail_case_id
|
||||
self.name = name
|
||||
self.testruns = testruns
|
||||
self.geth_paths = geth_paths
|
||||
self.logs_paths = logs_paths
|
||||
self.group_name = grop_name
|
||||
self.secured = secured
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ from os import environ
|
|||
from sys import argv
|
||||
|
||||
import emoji
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from support.base_test_report import BaseTestReport
|
||||
|
@ -214,9 +213,9 @@ class TestrailReport(BaseTestReport):
|
|||
if re.findall(pattern, res['comment']):
|
||||
res_id = res['id']
|
||||
try:
|
||||
for geth in test.geth_paths.keys():
|
||||
for log in test.logs_paths.keys():
|
||||
self.add_attachment(method='add_attachment_to_result/%s' % str(res_id),
|
||||
path=test.geth_paths[geth])
|
||||
path=test.logs_paths[log])
|
||||
except (AttributeError, FileNotFoundError):
|
||||
pass
|
||||
break
|
||||
|
|
|
@ -111,12 +111,13 @@ def get_app_path():
|
|||
return app_path
|
||||
|
||||
|
||||
def get_geth_path():
|
||||
return get_app_path() + 'geth.log'
|
||||
|
||||
|
||||
def pull_geth(driver):
|
||||
result = driver.pull_file(get_geth_path())
|
||||
result = driver.pull_file(get_app_path() + 'geth.log')
|
||||
return base64.b64decode(result)
|
||||
|
||||
|
||||
def pull_requests_log(driver):
|
||||
result = driver.pull_file(get_app_path() + 'requests.log')
|
||||
return base64.b64decode(result)
|
||||
|
||||
|
||||
|
@ -377,21 +378,23 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
|
|||
test_suite_data.current_test.group_name = self.__class__.__name__
|
||||
|
||||
def teardown_method(self, method):
|
||||
geth_names, geth_contents = [], []
|
||||
log_names, log_contents = [], []
|
||||
for driver in self.drivers:
|
||||
try:
|
||||
self.print_sauce_lab_info(self.drivers[driver])
|
||||
self.add_alert_text_to_report(self.drivers[driver])
|
||||
geth_names.append(
|
||||
log_names.append(
|
||||
'%s_geth%s.log' % (test_suite_data.current_test.name, str(self.drivers[driver].number)))
|
||||
geth_contents.append(pull_geth(self.drivers[driver]))
|
||||
|
||||
log_contents.append(pull_geth(self.drivers[driver]))
|
||||
log_names.append(
|
||||
'%s_requests%s.log' % (test_suite_data.current_test.name, str(self.drivers[driver].number)))
|
||||
log_contents.append(pull_requests_log(self.drivers[driver]))
|
||||
except (WebDriverException, AttributeError, RemoteDisconnected, ProtocolError):
|
||||
pass
|
||||
finally:
|
||||
try:
|
||||
geth = {geth_names[i]: geth_contents[i] for i in range(len(geth_names))}
|
||||
test_suite_data.current_test.geth_paths = github_report.save_geth(geth)
|
||||
logs = {log_names[i]: log_contents[i] for i in range(len(log_names))}
|
||||
test_suite_data.current_test.logs_paths = github_report.save_logs(logs)
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
|
@ -413,11 +416,14 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
|
|||
group_setup_failed = True
|
||||
else:
|
||||
group_setup_failed = False
|
||||
geth_contents = list()
|
||||
log_contents, log_names = list(), list()
|
||||
try:
|
||||
for _, driver in cls.drivers.items():
|
||||
for i, driver in cls.drivers.items():
|
||||
if group_setup_failed:
|
||||
geth_contents.append(pull_geth(driver=driver))
|
||||
log_contents.append(pull_geth(driver=driver))
|
||||
log_names.append('%s_geth%s.log' % (cls.__name__, i))
|
||||
log_contents.append(pull_requests_log(driver=driver))
|
||||
log_names.append('%s_requests%s.log' % (cls.__name__, i))
|
||||
session_id = driver.session_id
|
||||
try:
|
||||
sauce.jobs.update_job(username=sauce_username, job_id=session_id, name=cls.__name__)
|
||||
|
@ -449,13 +455,12 @@ class SauceSharedMultipleDeviceTestCase(AbstractTestCase):
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
geth_names = ['%s_geth%s.log' % (cls.__name__, i) for i in range(len(geth_contents))]
|
||||
geth = dict(zip(geth_names, geth_contents))
|
||||
geth_paths = github_report.save_geth(geth)
|
||||
logs = dict(zip(log_names, log_contents))
|
||||
logs_paths = github_report.save_logs(logs)
|
||||
|
||||
for test in test_suite_data.tests:
|
||||
if group_setup_failed:
|
||||
test.geth_paths = geth_paths
|
||||
test.logs_paths = logs_paths
|
||||
github_report.save_test(test)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue