22from colorama import Fore , init
33
44from . import TestReporter
5- from ..test_case import TestCase
5+ from ..test_case import TestCase , SkippedResult , TimedoutResult
66from ..test_suite import TestSuite
77from ..runtime_adapter import RuntimeVersion
88
@@ -19,18 +19,21 @@ def __init__(self, colored: bool = True) -> None:
1919 self ._colored = colored
2020
2121 def report_test (self , test : TestCase ) -> None :
22- if test .result .failed :
23- self ._print_fail (f"Test { test .name } failed" )
24- for reason in test .result .failures :
25- self ._print_fail (f" [{ reason .type } ] { reason .message } " )
26- print ("STDOUT:" )
27- print (test .result .output .stdout )
28- print ("STDERR:" )
29- print (test .result .output .stderr )
30- elif test .result .is_executed :
31- self ._print_pass (f"Test { test .name } passed" )
32- else :
22+ if isinstance (test .result , TimedoutResult ):
23+ self ._print_fail (f"Test { test .name } timed out" )
24+ elif isinstance (test .result , SkippedResult ):
3325 self ._print_skip (f"Test { test .name } skipped" )
26+ else :
27+ if test .result .failed :
28+ self ._print_fail (f"Test { test .name } failed" )
29+ for reason in test .result .failures :
30+ self ._print_fail (f" [{ reason .type } ] { reason .message } " )
31+ print ("STDOUT:" )
32+ print (test .result .output .stdout )
33+ print ("STDERR:" )
34+ print (test .result .output .stderr )
35+ else :
36+ self ._print_pass (f"Test { test .name } passed" )
3437
3538 def report_test_suite (self , test_suite : TestSuite ) -> None :
3639 self ._test_suites .append (test_suite )
@@ -40,29 +43,31 @@ def finalize(self, version: RuntimeVersion) -> None:
4043 print ("===== Test results =====" )
4144 print (f"Runtime: { version .name } { version .version } " )
4245
43- total_skip = total_pass = total_fail = pass_suite = 0
46+ total_skip = total_pass = total_fail = total_timedout = pass_suite = 0
4447
4548 for suite in self ._test_suites :
4649 total_pass += suite .pass_count
4750 total_fail += suite .fail_count
4851 total_skip += suite .skip_count
52+ total_timedout += suite .timedout_count
4953
50- if suite .fail_count == 0 :
54+ if suite .fail_count == 0 and suite . timedout_count == 0 :
5155 pass_suite += 1
5256
5357 print (f"Suite: { suite .name } " )
5458 print (f" Total: { suite .test_count } " )
55- self ._print_pass (f" Passed: { suite .pass_count } " )
56- self ._print_fail (f" Failed: { suite .fail_count } " )
57- self ._print_skip (f" Skipped: { suite .skip_count } " )
59+ self ._print_pass (f" Passed: { suite .pass_count } " )
60+ self ._print_fail (f" Failed: { suite .fail_count } " )
61+ self ._print_skip (f" Skipped: { suite .skip_count } " )
62+ self ._print_fail (f" Timed out: { suite .timedout_count } " )
5863 print ("" )
5964
6065 print (
61- f"Test suites: { self ._get_summary (len (self ._test_suites ) - pass_suite , pass_suite , 0 )} "
66+ f"Test suites: { self ._get_summary (len (self ._test_suites ) - pass_suite , pass_suite , 0 , 0 )} "
6267 )
63- print (f"Tests: { self ._get_summary (total_fail , total_pass , total_skip )} " )
68+ print (f"Tests: { self ._get_summary (total_fail , total_pass , total_skip , total_timedout )} " )
6469
65- def _get_summary (self , fail_count : int , pass_count : int , skip_count : int ) -> str :
70+ def _get_summary (self , fail_count : int , pass_count : int , skip_count : int , timedout_count : int ) -> str :
6671 items : List [str ] = []
6772
6873 if fail_count :
@@ -71,6 +76,8 @@ def _get_summary(self, fail_count: int, pass_count: int, skip_count: int) -> str
7176 items .append (f"{ self ._pass_color } { pass_count } passed" )
7277 if skip_count :
7378 items .append (f"{ self ._skip_color } { skip_count } skipped" )
79+ if timedout_count :
80+ items .append (f"{ self ._fail_color } { timedout_count } timed out" )
7481
7582 items .append (f"{ skip_count } total" )
7683 return ", " .join (items )
0 commit comments