1- from typing import Any , Dict
1+ from typing import Any , Dict , Iterator , Union , cast
22
33from .debugger import Debugger
4+ from .types import Event
45
56
67class ListenerV2 :
@@ -11,6 +12,14 @@ def __init__(self, no_debug: bool = False) -> None:
1112 self .debug = not no_debug
1213
1314 def start_suite (self , name : str , attributes : Dict [str , Any ]) -> None :
15+ Debugger .instance ().send_event (
16+ self ,
17+ Event (
18+ event = "robotStarted" ,
19+ body = dict (attributes ),
20+ ),
21+ )
22+
1423 Debugger .instance ().start_output_group (name , attributes , "SUITE" )
1524
1625 if self .debug :
@@ -22,7 +31,23 @@ def end_suite(self, name: str, attributes: Dict[str, Any]) -> None:
2231
2332 Debugger .instance ().end_output_group (name , attributes )
2433
34+ Debugger .instance ().send_event (
35+ self ,
36+ Event (
37+ event = "robotEnded" ,
38+ body = dict (attributes ),
39+ ),
40+ )
41+
2542 def start_test (self , name : str , attributes : Dict [str , Any ]) -> None :
43+ Debugger .instance ().send_event (
44+ self ,
45+ Event (
46+ event = "robotStarted" ,
47+ body = dict (attributes ),
48+ ),
49+ )
50+
2651 Debugger .instance ().start_output_group (name , attributes , "TEST" )
2752
2853 if self .debug :
@@ -34,6 +59,14 @@ def end_test(self, name: str, attributes: Dict[str, Any]) -> None:
3459
3560 Debugger .instance ().end_output_group (name , attributes )
3661
62+ Debugger .instance ().send_event (
63+ self ,
64+ Event (
65+ event = "robotEnded" ,
66+ body = dict (attributes ),
67+ ),
68+ )
69+
3770 def start_keyword (self , name : str , attributes : Dict [str , Any ]) -> None :
3871 Debugger .instance ().start_output_group (
3972 f"{ name } ({ ', ' .join (repr (v ) for v in attributes .get ('args' , []))} )" ,
@@ -82,3 +115,29 @@ def debug_file(self, path: str) -> None:
82115
83116 def close (self ) -> None :
84117 pass
118+
119+
120+ class ListenerV3 :
121+ ROBOT_LISTENER_API_VERSION = "3"
122+
123+ def start_suite (self , data : Any , result : Any ) -> None :
124+ from robot .running import TestCase , TestSuite
125+
126+ def enqueue (item : Union [TestSuite , TestCase ]) -> Iterator [str ]:
127+ if isinstance (item , TestSuite ):
128+ for s in item .suites :
129+ yield from enqueue (s )
130+ for s in item .tests :
131+ yield from enqueue (s )
132+
133+ yield item .longname
134+
135+ items = [i for i in enqueue (cast (TestSuite , data ))]
136+
137+ Debugger .instance ().send_event (
138+ self ,
139+ Event (
140+ event = "robotEnqueued" ,
141+ body = {"items" : items },
142+ ),
143+ )
0 commit comments