2020import threading
2121import traceback
2222from collections import OrderedDict
23+ from enum import Enum
2324from functools import wraps
2425from os import curdir
2526from time import sleep , time
2627from typing import Any , Callable , Generator , Optional , Union
2728
2829from _pytest .doctest import DoctestItem
29- from aenum import Enum , auto , unique
3030from py .path import local
3131from pytest import Class , Function , Item , Module , Package , PytestWarning , Session
3232from reportportal_client .aio import Task
7474except 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
7878from reportportal_client .helpers import dict_to_payload , gen_attributes , get_launch_sys_attrs , get_package_version
7979
8080LOGGER = logging .getLogger (__name__ )
@@ -125,25 +125,23 @@ def trim_docstring(docstring: str) -> str:
125125 return "\n " .join (trimmed )
126126
127127
128- @unique
129128class LeafType (Enum ):
130129 """This class stores test item path types."""
131130
132- DIR = auto ()
133- FILE = auto ()
134- CODE = auto ()
135- ROOT = auto ()
136- SUITE = auto ()
137- NESTED = auto ()
131+ DIR = 1
132+ FILE = 2
133+ CODE = 3
134+ ROOT = 4
135+ SUITE = 5
136+ NESTED = 6
138137
139138
140- @unique
141139class ExecStatus (Enum ):
142140 """This class stores test item path types."""
143141
144- CREATED = auto ()
145- IN_PROGRESS = auto ()
146- FINISHED = auto ()
142+ CREATED = 1
143+ IN_PROGRESS = 2
144+ FINISHED = 3
147145
148146
149147def check_rp_enabled (func ):
@@ -190,7 +188,7 @@ def __init__(self, agent_config: AgentConfig) -> None:
190188 self ._start_tracker = set ()
191189 self ._launch_id = None
192190 self .agent_name = "pytest-reportportal"
193- self .agent_version = get_package_version (self .agent_name )
191+ self .agent_version = get_package_version (self .agent_name ) or "None"
194192 self .ignored_attributes = []
195193 self .parent_item_id = None
196194 self .rp = None
@@ -221,7 +219,7 @@ def _get_launch_attributes(self, ini_attrs: Optional[list[dict[str, str]]]) -> l
221219 attributes = ini_attrs or []
222220 system_attributes = get_launch_sys_attrs ()
223221 system_attributes ["agent" ] = "{}|{}" .format (self .agent_name , self .agent_version )
224- return attributes + dict_to_payload (system_attributes )
222+ return attributes + ( dict_to_payload (system_attributes ) or [] )
225223
226224 def _build_start_launch_rq (self ) -> dict [str , Any ]:
227225 rp_launch_attributes = self ._config .rp_launch_attributes
@@ -366,6 +364,7 @@ def _get_scenario_template(self, scenario: Scenario) -> Optional[ScenarioTemplat
366364 break
367365 if scenario_template and isinstance (scenario_template , ScenarioTemplate ):
368366 return scenario_template
367+ return None
369368
370369 def _get_method_name (self , item : Item ) -> str :
371370 """Get the original test method name.
@@ -650,20 +649,20 @@ def _get_test_case_id(
650649 else :
651650 return base_name + param_str
652651
653- def _get_issue_ids (self , mark ):
654- 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 []
655654 if not isinstance (issue_ids , list ):
656655 issue_ids = [issue_ids ]
657656 return issue_ids
658657
659- def _get_issue_urls (self , mark , default_url ) :
658+ def _get_issue_urls (self , mark , default_url : str ) -> list [ Optional [ str ]] :
660659 issue_ids = self ._get_issue_ids (mark )
661660 if not issue_ids :
662- return None
661+ return []
663662 mark_url = mark .kwargs .get ("url" , None ) or default_url
664- 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 ]
665664
666- def _get_issue_description_line (self , mark , default_url ) :
665+ def _get_issue_description_line (self , mark , default_url : str ) -> str :
667666 issue_ids = self ._get_issue_ids (mark )
668667 if not issue_ids :
669668 return mark .kwargs ["reason" ]
@@ -693,7 +692,7 @@ def _get_issue(self, mark: Mark) -> Optional[Issue]:
693692 issue_short_name = mark .kwargs ["issue_type" ]
694693
695694 # default value
696- 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 )
697696
698697 registered_issues = self .issue_types
699698 issue = None
@@ -824,7 +823,8 @@ def _process_attributes(self, item: Item) -> list[dict[str, Any]]:
824823 test_attributes = self ._config .rp_tests_attributes
825824 if test_attributes :
826825 attributes = {
827- (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 [])
828828 }
829829 else :
830830 attributes = set ()
@@ -1420,7 +1420,7 @@ def start(self) -> None:
14201420 if self ._config .rp_launch_uuid :
14211421 launch_id = self ._config .rp_launch_uuid
14221422 self .rp = create_client (
1423- client_type = self ._config .rp_client_type or ClientType . SYNC ,
1423+ client_type = self ._config .rp_client_type ,
14241424 endpoint = self ._config .rp_endpoint ,
14251425 project = self ._config .rp_project ,
14261426 api_key = self ._config .rp_api_key ,
@@ -1431,7 +1431,7 @@ def start(self) -> None:
14311431 launch_uuid = launch_id ,
14321432 log_batch_payload_limit = self ._config .rp_log_batch_payload_limit ,
14331433 launch_uuid_print = self ._config .rp_launch_uuid_print ,
1434- print_output = self ._config .rp_launch_uuid_print_output ,
1434+ print_output = self ._config .rp_launch_uuid_print_output or OutputType . STDOUT ,
14351435 http_timeout = self ._config .rp_http_timeout ,
14361436 mode = self ._config .rp_mode ,
14371437 # OAuth 2.0 parameters
0 commit comments