14
14
"""Base test case used for xds test suites."""
15
15
import inspect
16
16
import traceback
17
- from typing import Optional , Union
18
- import unittest
17
+ from typing import Optional , TypeVar , Union
18
+ import unittest . case
19
19
20
20
from absl import logging
21
21
from absl .testing import absltest
22
+ from typing_extensions import override
23
+
24
+ # Aliases
25
+ _OutcomeType : TypeVar = unittest .case ._Outcome # noqa
22
26
23
27
24
28
class BaseTestCase (absltest .TestCase ):
25
- # @override
29
+ @override
30
+ def tearDown (self ) -> None :
31
+ if not (outcome := self ._get_outcome ()):
32
+ return
33
+ if outcome .success :
34
+ logging .info (
35
+ "----- PSM Test Case PASSED: %s -----\n " , self .test_name
36
+ )
37
+ return
38
+
39
+ test_errors = [error for test , error in outcome .errors if test is self ]
40
+ logging .error ("----- PSM Test Case FAILED: %s -----" , self .test_name )
41
+ self ._log_test_errors (test_errors )
42
+
43
+ @override
26
44
def run (self , result : Optional [unittest .TestResult ] = None ) -> None :
27
45
super ().run (result )
28
46
# TODO(sergiitk): should this method be returning result? See
@@ -40,17 +58,18 @@ def run(self, result: Optional[unittest.TestResult] = None) -> None:
40
58
)
41
59
# Assume one test case will only have one status.
42
60
if test_errors or test_failures :
43
- total_errors = len (test_errors ) + len (test_failures )
44
- logging .error (
45
- "----- PSM Test Case FAILED: %s -----" , self .test_name
46
- )
47
- self ._log_test_errors (test_errors , is_unexpected = True )
48
- self ._log_test_errors (test_failures )
49
- logging .info (
50
- "----- PSM Test Case %s Error Count: %s -----" ,
51
- self .test_name ,
52
- total_errors ,
53
- )
61
+ pass
62
+ # total_errors = len(test_errors) + len(test_failures)
63
+ # logging.error(
64
+ # "----- PSM Test Case FAILED: %s -----", self.test_name
65
+ # )
66
+ # self._log_test_errors(test_errors, is_unexpected=True)
67
+ # self._log_test_errors(test_failures)
68
+ # logging.info(
69
+ # "----- PSM Test Case %s Error Count: %s -----",
70
+ # self.test_name,
71
+ # total_errors,
72
+ # )
54
73
elif test_unexpected_successes :
55
74
logging .error (
56
75
"----- PSM Test Case UNEXPECTEDLY SUCCEEDED: %s -----\n " ,
@@ -69,6 +88,9 @@ def run(self, result: Optional[unittest.TestResult] = None) -> None:
69
88
self .test_name ,
70
89
)
71
90
91
+ def _get_outcome (self ) -> Optional [_OutcomeType ]:
92
+ return getattr (self , "_outcome" , None )
93
+
72
94
@property
73
95
def test_name (self ) -> str :
74
96
"""Pretty test name (details in the description).
0 commit comments