33
44import click
55from dohq_teamcity import TeamCity
6+ from teamcity .messages import TeamcityServiceMessages
67
78from scripts .trigger_auto_tests .utils .helpers import (
89 AutoTestsInfo ,
@@ -22,37 +23,44 @@ def main(tc_user: str, tc_password: str):
2223 triggered_builds : dict [str , int ] = {}
2324 tc = TeamCity (TC_URL , auth = (tc_user , tc_password ))
2425 tests_info = AutoTestsInfo .get_current (tc )
26+ tc_msg = TeamcityServiceMessages ()
2527 if tests_info .re_run_builds :
2628 click .echo ("Re run failed builds" )
2729 else :
2830 click .echo ("Run automated tests" )
2931
30- for shell_name in tests_info .supported_shells :
31- try :
32- build_id = _run_tests_for_shell (tc , shell_name , tests_info )
33- triggered_builds [shell_name ] = build_id
34- except Exception as e :
35- errors .append (e )
36- click .echo (e , err = True )
32+ tc_msg .testCount (len (tests_info .supported_shells ))
33+ with tc_msg .testSuite ("Automation tests" ):
34+ for shell_name in tests_info .supported_shells :
35+ try :
36+ build_id = _run_tests_for_shell (tc , tc_msg , shell_name , tests_info )
37+ triggered_builds [shell_name ] = build_id
38+ except Exception as e :
39+ errors .append (e )
40+ click .echo (e , err = True )
3741
38- builds_statuses , new_errors = _wait_build_finish (tc , triggered_builds )
39- errors .extend (new_errors )
42+ builds_statuses , new_errors = _wait_build_finish (tc , tc_msg , triggered_builds )
43+ errors .extend (new_errors )
4044
41- if errors :
42- raise Exception ("There were errors running automation tests." )
45+ if errors :
46+ raise Exception ("There were errors running automation tests." )
4347 return all (builds_statuses .values ())
4448
4549
4650def _run_tests_for_shell (
47- tc : TeamCity , shell_name : str , tests_info : AutoTestsInfo
51+ tc : TeamCity ,
52+ tc_msg : TeamcityServiceMessages ,
53+ shell_name : str ,
54+ tests_info : AutoTestsInfo ,
4855) -> Optional [int ]:
4956 build_id = None
5057 if is_shell_uses_package (shell_name , tests_info ):
5158 if tests_info .re_run_builds :
5259 if is_last_build_successful (tc , shell_name , tests_info ):
53- click .echo (
60+ tc_msg .testIgnored (
61+ shell_name ,
5462 f"{ shell_name } last auto tests for this package and commit "
55- f"id was successful, skip it"
63+ f"id was successful, skip it" ,
5664 )
5765 else :
5866 click .echo (f"{ shell_name } Re run automation tests" )
@@ -61,27 +69,35 @@ def _run_tests_for_shell(
6169 click .echo (f"{ shell_name } Automation tests build triggering" )
6270 build_id = trigger_auto_tests_build2 (tc , shell_name , tests_info )
6371 else :
64- click .echo (f"{ shell_name } is not uses package with this version, skipped tests" )
72+ tc_msg .testIgnored (
73+ shell_name ,
74+ f"{ shell_name } is not uses package with this version, skipped tests" ,
75+ )
6576 return build_id
6677
6778
6879def _wait_build_finish (
69- tc : TeamCity , triggered_builds : dict [str , int ]
80+ tc : TeamCity , tc_msg : TeamcityServiceMessages , triggered_builds : dict [str , int ]
7081) -> tuple [dict [str , bool ], list [Exception ]]:
7182 builds_statuses = {}
7283 errors = []
84+ start_time = time .time ()
7385 while triggered_builds :
7486 time .sleep (BUILDS_CHECK_DELAY )
7587 for shell_name , build_id in triggered_builds .copy ().items ():
7688 try :
7789 build = tc .builds .get (f"id:{ build_id } " )
7890 if is_build_finished (build ):
79- click .echo (
80- f"{ shell_name } Automation tests is finished "
81- f"with status { build .status } "
82- )
83- builds_statuses [shell_name ] = is_build_success (build )
84- triggered_builds .pop (shell_name )
91+ with tc_msg .test (shell_name , testDuration = time .time () - start_time ):
92+ is_success = is_build_success (build )
93+ builds_statuses [shell_name ] = is_success
94+ triggered_builds .pop (shell_name )
95+ if not is_success :
96+ tc_msg .testFailed (
97+ shell_name ,
98+ f"{ shell_name } Automation tests is finished"
99+ f" with status { build .status } " ,
100+ )
85101 except Exception as e :
86102 errors .append (e )
87103 click .echo (e , err = True )
0 commit comments