55from contextlib import contextmanager
66from functools import wraps
77
8- from reportportal_client .client import RPClient
9-
108from reportportal_client ._local import current , set_current
119from reportportal_client import RPLogger
10+ from reportportal_client .core .worker import APIWorker
11+
12+
13+ def is_api_worker (target ):
14+ """Check if target is an RP worker thread."""
15+ if target :
16+ method_name = getattr (target , '__name__' , None )
17+ method_self = getattr (target , '__self__' , None )
18+ if method_name == '_monitor' and method_self :
19+ clazz = getattr (method_self , '__class__' , None )
20+ if clazz is APIWorker :
21+ return True
22+ return False
1223
1324
1425@contextmanager
@@ -30,7 +41,8 @@ def wrap_start(original_func):
3041 def _start (self , * args , ** kwargs ):
3142 """Save the invoking thread's client if there is one."""
3243 # Prevent an endless loop of workers being spawned
33- if "_monitor" not in self .name :
44+ target = getattr (self , '_target' , None )
45+ if not is_api_worker (self ) and not is_api_worker (target ):
3446 current_client = current ()
3547 self .parent_rp_client = current_client
3648 return original_func (self , * args , ** kwargs )
@@ -48,20 +60,7 @@ def _run(self, *args, **kwargs):
4860 and not current ()
4961 ):
5062 parent = self .parent_rp_client
51- client = RPClient (
52- endpoint = parent .endpoint ,
53- project = parent .project ,
54- token = parent .token ,
55- log_batch_size = parent .log_batch_size ,
56- is_skipped_an_issue = parent .is_skipped_an_issue ,
57- verify_ssl = parent .verify_ssl ,
58- retries = config .rp_retries ,
59- launch_id = parent .launch_id
60- )
61- if parent .current_item ():
62- client ._item_stack .append (
63- parent .current_item ()
64- )
63+ client = parent .clone ()
6564 client .start ()
6665 try :
6766 return original_func (self , * args , ** kwargs )
0 commit comments