2525from _pytest .unittest import TestCaseFunction , UnitTestCase
2626
2727from reportportal_client import ReportPortalService
28+ from reportportal_client .service import _dict_to_payload
2829from six import with_metaclass
2930from six .moves import queue
3031
@@ -83,7 +84,7 @@ def __init__(self):
8384 self ._item_parts = {}
8485 self ._loglevels = ('TRACE' , 'DEBUG' , 'INFO' , 'WARN' , 'ERROR' )
8586 self .ignore_errors = True
86- self .ignored_tags = []
87+ self .ignored_attributes = []
8788 self .log_batch_size = 20
8889 self .log_item_id = None
8990 self .parent_item_id = None
@@ -112,17 +113,17 @@ def init_service(self,
112113 uuid ,
113114 log_batch_size ,
114115 ignore_errors ,
115- ignored_tags ,
116+ ignored_attributes ,
116117 verify_ssl = True ,
117118 retries = 0 ):
118119 """Update self.rp with the instance of the ReportPortalService."""
119120 self ._errors = queue .Queue ()
120121 if self .rp is None :
121122 self .ignore_errors = ignore_errors
122- self .ignored_tags = ignored_tags
123+ self .ignored_attributes = ignored_attributes
123124 if self .rp_supports_parameters :
124- self .ignored_tags = list (
125- set (ignored_tags ).union ({'parametrize' }))
125+ self .ignored_attributes = list (
126+ set (ignored_attributes ).union ({'parametrize' }))
126127 log .debug ('ReportPortal - Init service: endpoint=%s, '
127128 'project=%s, uuid=%s' , endpoint , project , uuid )
128129 self .rp = ReportPortalService (
@@ -143,15 +144,14 @@ def start_launch(self,
143144 launch_name ,
144145 mode = None ,
145146 description = None ,
147+ attributes = None ,
146148 ** kwargs ):
147149 self ._stop_if_necessary ()
148150 if self .rp is None :
149151 return
150152
151- system_info = self .rp .get_system_information (self ._agent_name )
152- system_info ['system' ] = True
153153 sl_pt = {
154- 'attributes' : system_info ,
154+ 'attributes' : self . _get_launch_attributes ( attributes ) ,
155155 'name' : launch_name ,
156156 'start_time' : timestamp (),
157157 'description' : description ,
@@ -449,9 +449,22 @@ def _get_item_dirs(item):
449449
450450 return dir_list
451451
452+ def _get_launch_attributes (self , ini_attrs ):
453+ """Generate launch attributes in the format supported by the client.
454+
455+ :param list ini_attrs: List for attributes from the pytest.ini file
456+ """
457+ attributes = ini_attrs or []
458+
459+ system_info = self .rp .get_system_information (self ._agent_name )
460+ system_info ['system' ] = True
461+ system_attributes = _dict_to_payload (system_info )
462+
463+ return attributes + system_attributes
464+
452465 def _get_item_markers (self , item ):
453466 # Try to extract names of @pytest.mark.* decorators used for test item
454- # and exclude those which present in rp_ignore_tags parameter
467+ # and exclude those which present in rp_ignore_attributes parameter
455468 def get_marker_value (item , keyword ):
456469 try :
457470 marker = item .get_closest_marker (keyword )
@@ -466,13 +479,13 @@ def get_marker_value(item, keyword):
466479 get_marker = getattr (item , "get_closest_marker" )
467480 except AttributeError :
468481 get_marker = getattr (item , "get_marker" )
469- tags = [{"value" : get_marker_value (item , k )}
470- for k in item .keywords if get_marker (k ) is not None
471- and k not in self .ignored_tags ]
482+ attributes = [{"value" : get_marker_value (item , k )}
483+ for k in item .keywords if get_marker (k ) is not None
484+ and k not in self .ignored_attributes ]
472485
473- tags .extend ([{"value" : tag }
474- for tag in item .session .config .getini ('rp_tests_tags ' )])
475- return tags
486+ attributes .extend ([{"value" : tag } for tag in
487+ item .session .config .getini ('rp_tests_attributes ' )])
488+ return attributes
476489
477490 def _get_parameters (self , item ):
478491 return item .callspec .params if hasattr (item , 'callspec' ) else None
0 commit comments