Skip to content

Commit 20486d4

Browse files
committed
Some type fixes
1 parent cde8362 commit 20486d4

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

pytest_reportportal/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AgentConfig:
2828
"""Storage for the RP agent initialization attributes."""
2929

3030
rp_enabled: bool
31-
rp_client_type: Optional[ClientType]
31+
rp_client_type: ClientType
3232
rp_rerun: Optional[bool]
3333
pconfig: Config
3434
rp_endpoint: str
@@ -72,7 +72,7 @@ class AgentConfig:
7272
rp_verify_ssl: Union[bool, str]
7373
rp_launch_timeout: int
7474
rp_launch_uuid_print: bool
75-
rp_launch_uuid_print_output: Optional[OutputType]
75+
rp_launch_uuid_print_output: OutputType
7676
rp_http_timeout: Optional[Union[tuple[float, float], float]]
7777
rp_report_fixtures: bool
7878

@@ -174,7 +174,7 @@ def __init__(self, pytest_config: Config) -> None:
174174

175175
self.rp_launch_uuid_print = to_bool(self.find_option(pytest_config, "rp_launch_uuid_print") or "False")
176176
print_output = self.find_option(pytest_config, "rp_launch_uuid_print_output")
177-
self.rp_launch_uuid_print_output = OutputType[print_output.upper()] if print_output else None
177+
self.rp_launch_uuid_print_output = OutputType[print_output.upper()] if print_output else OutputType.STDOUT
178178
client_type = self.find_option(pytest_config, "rp_client_type")
179179
self.rp_client_type = ClientType[client_type.upper()] if client_type else ClientType.SYNC
180180

pytest_reportportal/service.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
except ImportError:
7575
Rule = type("dummy", (), {}) # Old pytest-bdd versions do not have Rule
7676

77-
from reportportal_client import RP, ClientType, create_client
77+
from reportportal_client import RP, OutputType, create_client
7878
from reportportal_client.helpers import dict_to_payload, gen_attributes, get_launch_sys_attrs, get_package_version
7979

8080
LOGGER = logging.getLogger(__name__)
@@ -188,7 +188,7 @@ def __init__(self, agent_config: AgentConfig) -> None:
188188
self._start_tracker = set()
189189
self._launch_id = None
190190
self.agent_name = "pytest-reportportal"
191-
self.agent_version = get_package_version(self.agent_name)
191+
self.agent_version = get_package_version(self.agent_name) or "None"
192192
self.ignored_attributes = []
193193
self.parent_item_id = None
194194
self.rp = None
@@ -219,7 +219,7 @@ def _get_launch_attributes(self, ini_attrs: Optional[list[dict[str, str]]]) -> l
219219
attributes = ini_attrs or []
220220
system_attributes = get_launch_sys_attrs()
221221
system_attributes["agent"] = "{}|{}".format(self.agent_name, self.agent_version)
222-
return attributes + dict_to_payload(system_attributes)
222+
return attributes + (dict_to_payload(system_attributes) or [])
223223

224224
def _build_start_launch_rq(self) -> dict[str, Any]:
225225
rp_launch_attributes = self._config.rp_launch_attributes
@@ -364,6 +364,7 @@ def _get_scenario_template(self, scenario: Scenario) -> Optional[ScenarioTemplat
364364
break
365365
if scenario_template and isinstance(scenario_template, ScenarioTemplate):
366366
return scenario_template
367+
return None
367368

368369
def _get_method_name(self, item: Item) -> str:
369370
"""Get the original test method name.
@@ -648,20 +649,20 @@ def _get_test_case_id(
648649
else:
649650
return base_name + param_str
650651

651-
def _get_issue_ids(self, mark):
652-
issue_ids = mark.kwargs.get("issue_id", [])
652+
def _get_issue_ids(self, mark) -> list[Any]:
653+
issue_ids = mark.kwargs.get("issue_id", []) or []
653654
if not isinstance(issue_ids, list):
654655
issue_ids = [issue_ids]
655656
return issue_ids
656657

657-
def _get_issue_urls(self, mark, default_url):
658+
def _get_issue_urls(self, mark, default_url: str) -> list[Optional[str]]:
658659
issue_ids = self._get_issue_ids(mark)
659660
if not issue_ids:
660-
return None
661+
return []
661662
mark_url = mark.kwargs.get("url", None) or default_url
662-
return [mark_url.format(issue_id=issue_id) if mark_url else None for issue_id in issue_ids]
663+
return [str(mark_url).format(issue_id=str(issue_id)) if mark_url else None for issue_id in issue_ids]
663664

664-
def _get_issue_description_line(self, mark, default_url):
665+
def _get_issue_description_line(self, mark, default_url: str) -> str:
665666
issue_ids = self._get_issue_ids(mark)
666667
if not issue_ids:
667668
return mark.kwargs["reason"]
@@ -691,7 +692,7 @@ def _get_issue(self, mark: Mark) -> Optional[Issue]:
691692
issue_short_name = mark.kwargs["issue_type"]
692693

693694
# default value
694-
issue_short_name = "TI" if issue_short_name is None else issue_short_name
695+
issue_short_name = "TI" if issue_short_name is None else str(issue_short_name)
695696

696697
registered_issues = self.issue_types
697698
issue = None
@@ -822,7 +823,8 @@ def _process_attributes(self, item: Item) -> list[dict[str, Any]]:
822823
test_attributes = self._config.rp_tests_attributes
823824
if test_attributes:
824825
attributes = {
825-
(attr.get("key", None), attr["value"]) for attr in gen_attributes(self._config.rp_tests_attributes)
826+
(attr.get("key", None), attr["value"])
827+
for attr in gen_attributes(self._config.rp_tests_attributes or [])
826828
}
827829
else:
828830
attributes = set()
@@ -1418,7 +1420,7 @@ def start(self) -> None:
14181420
if self._config.rp_launch_uuid:
14191421
launch_id = self._config.rp_launch_uuid
14201422
self.rp = create_client(
1421-
client_type=self._config.rp_client_type or ClientType.SYNC,
1423+
client_type=self._config.rp_client_type,
14221424
endpoint=self._config.rp_endpoint,
14231425
project=self._config.rp_project,
14241426
api_key=self._config.rp_api_key,
@@ -1429,7 +1431,7 @@ def start(self) -> None:
14291431
launch_uuid=launch_id,
14301432
log_batch_payload_limit=self._config.rp_log_batch_payload_limit,
14311433
launch_uuid_print=self._config.rp_launch_uuid_print,
1432-
print_output=self._config.rp_launch_uuid_print_output,
1434+
print_output=self._config.rp_launch_uuid_print_output or OutputType.STDOUT,
14331435
http_timeout=self._config.rp_http_timeout,
14341436
mode=self._config.rp_mode,
14351437
# OAuth 2.0 parameters

0 commit comments

Comments
 (0)