Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.3.4 - Retry on timeout #35

Merged
merged 11 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11.4"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11.5"]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -31,6 +31,8 @@ jobs:
pip install mypy reorder-python-imports
pip install wemake-python-styleguide reorder-python-imports
pip install black reorder-python-imports
pip install types-xmltodict
pip install types-requests
- name: Analysing the code with pylint
id: pylint
continue-on-error: true
Expand Down
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
4 changes: 4 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[mypy]

[mypy-testrail_api.*]
ignore_missing_imports = True
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ extend-ignore = """

[tool.pylint]
max-line-length = 120

[tool.mypy]

[[tool.mypy.overrides]]
module = "testrail_api.*"
ignore_missing_imports = true
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ xmltodict==0.13.0
testrail-api==1.12.0
plotly==5.16.1
psutil==5.9.5
atlassian-python-api==3.41.1
atlassian-python-api==3.41.2
kaleido==0.2.1
httplib2==0.22.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
google-api-python-client==2.97.0
google-auth-httplib2==0.1.1
google-auth-oauthlib==1.1.0
google-api-python-client==2.99.0
oauth2client==4.1.3
50 changes: 40 additions & 10 deletions testrail_api_reporter/engines/at_coverage_reporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Engine to generate obtain TestRail data and prepare reports """
from requests.exceptions import ReadTimeout
from testrail_api import TestRailAPI # type: ignore

from ..utils.case_stat import CaseStat
Expand Down Expand Up @@ -119,6 +120,7 @@ def __get_all_cases(
section_id=None,
priority_id=None,
debug=None,
retries=3,
):
"""
Wrapper to get all test cases for selected project, suite, section and priority
Expand All @@ -128,6 +130,7 @@ def __get_all_cases(
:param section_id: section id, integer, section where testcases should be found, optional
:param priority_id: priority, list of integers, id of priority for test case to search
:param debug: debug output is enabled, may be True or False, optional
:param retries: number of retries, integer, optional
:return: list with all cases
"""
project_id = project_id if project_id else self.__project
Expand All @@ -137,6 +140,7 @@ def __get_all_cases(
first_run = True
criteria = None
response = None
retry = 0
while criteria is not None or first_run:
if first_run:
try:
Expand All @@ -146,24 +150,50 @@ def __get_all_cases(
section_id=section_id,
priority_id=priority_id,
)
except ReadTimeout as error:
if retry < retries:
retry += 1
if debug:
print(f"Timeout error, retrying {retry}/{retries}...")
continue
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)}"
) from error
first_run = False
retry = 0
elif response["_links"]["next"] is not None: # pylint: disable=unsubscriptable-object
offset = int(
response["_links"]["next"] # pylint: disable=unsubscriptable-object
.partition("offset=")[2]
.partition("&")[0]
)
response = self.__api.cases.get_cases(
project_id=project_id,
suite_id=suite_id,
section_id=section_id,
priority_id=priority_id,
offset=offset,
)
try:
response = self.__api.cases.get_cases(
project_id=project_id,
suite_id=suite_id,
section_id=section_id,
priority_id=priority_id,
offset=offset,
)
except ReadTimeout as error:
if retry < retries:
retry += 1
if debug:
print(f"Timeout error, retrying {retry}/{retries}...")
continue
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)}"
) from error
retry = 0

cases_list = cases_list + response["cases"] # pylint: disable=unsubscriptable-object
criteria = response["_links"]["next"] # pylint: disable=unsubscriptable-object

Expand Down Expand Up @@ -212,7 +242,7 @@ def automation_state_report(
raise ValueError("No automation platforms specified, report aborted!")
debug = debug if debug is not None else self.__debug
if debug:
print("=== Staring generation of report for current automation state ===")
print("=== Starting generation of report for current automation state ===")
index = 0
results = []
for platform in automation_platforms:
Expand Down Expand Up @@ -260,7 +290,7 @@ def test_case_by_priority(self, project=None, suite=None, debug=None):
if not project:
raise ValueError("No project specified, report aborted!")
if debug:
print("=== Staring generation of report for test case priority distribution ===")
print("=== Starting generation of report for test case priority distribution ===")
results = []
for i in range(1, 5):
if debug:
Expand Down Expand Up @@ -297,7 +327,7 @@ def test_case_by_type(
debug = debug if debug is not None else self.__debug
project = project if project else self.__project
if debug:
print("=== Staring generation of report for test case area distribution ===")
print("=== Starting generation of report for test case area distribution ===")
index = 0
results = []
for platform in type_platforms:
Expand Down
Loading
Loading