Skip to content

Commit

Permalink
Linters fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wwakabobik committed Sep 14, 2023
1 parent 85f7cdb commit b87860c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
max-line-length=120

[MESSAGES CONTROL]
disable=E1101,R0913
disable=E1101,R0913,W0718
14 changes: 6 additions & 8 deletions testrail_api_reporter/engines/at_coverage_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ def __get_all_cases(
retry += 1
print(f"Timeout error, retrying {retry}/{retries}...")
continue
else:
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
except Exception as error: # pylint: disable=broad-except
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
Expand All @@ -184,10 +183,9 @@ def __get_all_cases(
retry += 1
print(f"Timeout error, retrying {retry}/{retries}...")
continue
else:
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
except Exception as error:
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
Expand Down
92 changes: 58 additions & 34 deletions testrail_api_reporter/engines/results_reporter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
""" Module for reporting results to TestRails from xml report results, obtained by pytest """
import datetime
from os.path import exists

Expand Down Expand Up @@ -117,8 +118,8 @@ def __ensure_automation_section(self, title="pytest"):
if first_run:
try:
response = self.__api.sections.get_sections(project_id=self.__project_id, suite_id=self.__suite_id)
except Exception as e:
print(f"Get sections failed. Please validate your settings!\nError{format_error(e)}")
except Exception as error:
print(f"Get sections failed. Please validate your settings!\nError{format_error(error)}")
self.__self_check()
return None
first_run = False
Expand All @@ -137,8 +138,8 @@ def __ensure_automation_section(self, title="pytest"):
item_id = self.__api.sections.add_section(
project_id=self.__project_id, suite_id=self.__suite_id, name=title
)["id"]
except Exception as e:
print(f"Can't add section. Something nasty happened. Error{format_error(e)}")
except Exception as error:
print(f"Can't add section. Something nasty happened. Error{format_error(error)}")
self.__self_check()
return None
print(f"No default automation folder is found, created new one with name'{title}'")
Expand Down Expand Up @@ -167,8 +168,8 @@ def __enrich_with_tc_num(self, xml_dict_list, tc_dict_list):
custom_automation_id=item["automation_id"],
)
]
except Exception as e:
print(f"Add case failed. Please validate your settings!\nError{format_error(e)}")
except Exception as error:
print(f"Add case failed. Please validate your settings!\nError{format_error(error)}")
self.__self_check()
return None
missed_tests_counter = missed_tests_counter + 1
Expand Down Expand Up @@ -213,12 +214,11 @@ def __get_all_auto_cases(self, retries=3):
retry += 1
print(f"Timeout error, retrying {retry}/{retries}...")
continue
else:
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
except Exception as e:
print(f"Get cases failed. Please validate your settings!\nError{format_error(e)}")
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
except Exception as error:
print(f"Get cases failed. Please validate your settings!\nError{format_error(error)}")
self.__self_check()
return None
first_run = False
Expand All @@ -234,10 +234,9 @@ def __get_all_auto_cases(self, retries=3):
retry += 1
print(f"Timeout error, retrying {retry}/{retries}...")
continue
else:
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
raise ValueError(
f"Get cases failed. Please validate your settings!\nError{format_error(error)}"
) from error
retry = 0
cases = response["cases"]
for item in cases:
Expand Down Expand Up @@ -321,20 +320,45 @@ def send_results(
return retval

def set_project_id(self, project_id):
"""
Set project id
:param project_id: project id, integer
"""
self.__project_id = project_id if self.__check_project(project_id=project_id) else None

def set_suite_id(self, suite_id):
"""
Set suite id
:param suite_id: suite id, integer
"""
if self.__check_project():
self.__suite_id = suite_id if self.__check_suite(suite_id=suite_id) else None

def set_xml_filename(self, xml_filename):
"""
Set xml filename
:param xml_filename: filename of xml report, string
"""
self.__xml_report = xml_filename if self.__check_report_exists(xml_report=xml_filename) else None

def set_at_report_section(self, section_name):
"""
Set section name for AT report
:param section_name: name of section, string
"""
if self.__check_project() and self.__check_suite():
self.__at_section = self.__ensure_automation_section(title=section_name)

def set_timestamp(self, new_timestamp):
"""
Set timestamp
:param new_timestamp: timestamp, string
"""
self.__timestamp = new_timestamp

def __check_project(self, project_id=None):
Expand All @@ -347,8 +371,8 @@ def __check_project(self, project_id=None):
retval = True
try:
self.__api.projects.get_project(project_id=project_id)
except Exception as e:
print(f"No such project is found, please set valid project ID.\nError{format_error(e)}")
except Exception as error:
print(f"No such project is found, please set valid project ID.\nError{format_error(error)}")
retval = False
return retval

Expand All @@ -362,8 +386,8 @@ def __check_suite(self, suite_id=None):
retval = True
try:
self.__api.suites.get_suite(suite_id=suite_id)
except Exception as e:
print(f"No such suite is found, please set valid AT report section.\nError{format_error(e)}")
except Exception as error:
print(f"No such suite is found, please set valid AT report section.\nError{format_error(error)}")
retval = False
return retval

Expand All @@ -377,8 +401,8 @@ def __check_section(self, section_id=None):
retval = True
try:
self.__api.sections.get_section(section_id=section_id)
except Exception as e:
print(f"No default section found, please set valid suite ID.\nError{format_error(e)}")
except Exception as error:
print(f"No default section found, please set valid suite ID.\nError{format_error(error)}")
retval = False
return retval

Expand Down Expand Up @@ -409,8 +433,8 @@ def __check_run_exists(self, run_id=None):
retval = True
try:
self.__api.runs.get_run(run_id=run_id)
except Exception as e:
print(f"No specified run found, please use correct one or use default (None)." f"\nError{format_error(e)}")
except Exception as error:
print(f"No specified run found, please use correct one or use default (None).\nError{format_error(error)}")
retval = False
return retval

Expand Down Expand Up @@ -438,8 +462,8 @@ def __search_for_run_by_name(self, title=None):
if first_run:
try:
response = self.__api.runs.get_runs(project_id=self.__project_id, suite_id=self.__suite_id)
except Exception as e:
print(f"Can't get run list. Something nasty happened.\nError{format_error(e)}")
except Exception as error:
print(f"Can't get run list. Something nasty happened.\nError{format_error(error)}")
break
first_run = False
elif response["_links"]["next"] is not None:
Expand All @@ -462,8 +486,8 @@ def __delete_run(self, run_id=None):
retval = True
try:
self.__api.runs.delete_run(run_id=run_id)
except Exception as e:
print(f"Can't delete run. Something nasty happened." f"\nError{format_error(e)}")
except Exception as error:
print(f"Can't delete run. Something nasty happened." f"\nError{format_error(error)}")
retval = False
return retval

Expand All @@ -486,8 +510,8 @@ def __add_run(self, title, cases_list=None, include_all=False):
include_all=include_all,
case_ids=cases_list,
)["id"]
except Exception as e:
print(f"Add run failed. Please validate your settings!\nError{format_error(e)}")
except Exception as error:
print(f"Add run failed. Please validate your settings!\nError{format_error(error)}")
self.__self_check()
return retval

Expand All @@ -502,8 +526,8 @@ def __add_results(self, run_id=None, results=None):
try:
self.__api.results.add_results_for_cases(run_id=run_id, results=results)
return run_id
except Exception as e:
print(f"Add results failed. Please validate your settings!\nError{format_error(e)}")
except Exception as error:
print(f"Add results failed. Please validate your settings!\nError{format_error(error)}")
self.__self_check()
self.__check_run_exists(run_id=run_id)
return retval
Expand Down Expand Up @@ -544,7 +568,7 @@ def __close_run(self, title=None, run_id=None):
try:
self.__api.runs.close_run(run_id=run_id)
print(f"Test run '{title}' is closed")
except Exception as e:
print(f"Can't close run! Something nasty happened.\nError{format_error(e)}")
except Exception as error:
print(f"Can't close run! Something nasty happened.\nError{format_error(error)}")
retval = False
return retval

0 comments on commit b87860c

Please sign in to comment.