2
2
from colorama import Fore , init
3
3
4
4
from . import TestReporter
5
- from ..test_case import TestCase
5
+ from ..test_case import TestCase , SkippedResult , TimedoutResult
6
6
from ..test_suite import TestSuite
7
7
from ..runtime_adapter import RuntimeVersion
8
8
@@ -19,18 +19,21 @@ def __init__(self, colored: bool = True) -> None:
19
19
self ._colored = colored
20
20
21
21
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 ):
33
25
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" )
34
37
35
38
def report_test_suite (self , test_suite : TestSuite ) -> None :
36
39
self ._test_suites .append (test_suite )
@@ -40,29 +43,31 @@ def finalize(self, version: RuntimeVersion) -> None:
40
43
print ("===== Test results =====" )
41
44
print (f"Runtime: { version .name } { version .version } " )
42
45
43
- total_skip = total_pass = total_fail = pass_suite = 0
46
+ total_skip = total_pass = total_fail = total_timedout = pass_suite = 0
44
47
45
48
for suite in self ._test_suites :
46
49
total_pass += suite .pass_count
47
50
total_fail += suite .fail_count
48
51
total_skip += suite .skip_count
52
+ total_timedout += suite .timedout_count
49
53
50
- if suite .fail_count == 0 :
54
+ if suite .fail_count == 0 and suite . timedout_count == 0 :
51
55
pass_suite += 1
52
56
53
57
print (f"Suite: { suite .name } " )
54
58
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 } " )
58
63
print ("" )
59
64
60
65
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 )} "
62
67
)
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 )} " )
64
69
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 :
66
71
items : List [str ] = []
67
72
68
73
if fail_count :
@@ -71,6 +76,8 @@ def _get_summary(self, fail_count: int, pass_count: int, skip_count: int) -> str
71
76
items .append (f"{ self ._pass_color } { pass_count } passed" )
72
77
if skip_count :
73
78
items .append (f"{ self ._skip_color } { skip_count } skipped" )
79
+ if timedout_count :
80
+ items .append (f"{ self ._fail_color } { timedout_count } timed out" )
74
81
75
82
items .append (f"{ skip_count } total" )
76
83
return ", " .join (items )
0 commit comments