@@ -126,10 +126,25 @@ class WebHostTestCaseMeta(type(unittest.TestCase)):
126
126
def __new__ (mcls , name , bases , dct ):
127
127
for attrname , attr in dct .items ():
128
128
if attrname .startswith ('test_' ) and callable (attr ):
129
-
130
- @functools .wraps (attr )
131
- def wrapper (self , * args , __meth__ = attr , ** kwargs ):
132
- return self ._run_test (__meth__ , * args , ** kwargs )
129
+ test_case_name = attrname .lstrip ('test_' )
130
+ test_case = attr
131
+
132
+ check_log_case_name = f'check_log_{ test_case_name } '
133
+ check_log_case = dct .get (check_log_case_name )
134
+
135
+ @functools .wraps (test_case )
136
+ def wrapper (self , * args , __meth__ = test_case ,
137
+ __check_log__ = check_log_case , ** kwargs ):
138
+ if __check_log__ is not None and callable (__check_log__ ):
139
+ # Check logging output for unit test scenarios
140
+ result = self ._run_test (__meth__ , * args , ** kwargs )
141
+ output_lines = self .host_out .splitlines ()
142
+ host_out = list (map (lambda s : s .strip (), output_lines ))
143
+ self ._run_test (__check_log__ , host_out = host_out )
144
+ return result
145
+ else :
146
+ # Check normal unit test
147
+ return self ._run_test (__meth__ , * args , ** kwargs )
133
148
134
149
dct [attrname ] = wrapper
135
150
@@ -188,16 +203,20 @@ def _run_test(self, test, *args, **kwargs):
188
203
self .host_stdout .read ()
189
204
last_pos = self .host_stdout .tell ()
190
205
206
+ test_exception = None
191
207
try :
192
208
test (self , * args , ** kwargs )
193
- except Exception :
194
- try :
195
- self .host_stdout .seek (last_pos )
196
- host_out = self .host_stdout .read ()
197
- self .host_stdout_logger .error (
198
- f'Captured WebHost stdout:\n { host_out } ' )
199
- finally :
200
- raise
209
+ except Exception as e :
210
+ test_exception = e
211
+
212
+ try :
213
+ self .host_stdout .seek (last_pos )
214
+ self .host_out = self .host_stdout .read ()
215
+ self .host_stdout_logger .error (
216
+ f'Captured WebHost stdout:\n { self .host_out } ' )
217
+ finally :
218
+ if test_exception is not None :
219
+ raise test_exception
201
220
202
221
203
222
class _MockWebHostServicer (protos .FunctionRpcServicer ):
@@ -725,7 +744,8 @@ def _setup_func_app(app_root):
725
744
f .write (HOST_JSON_TEMPLATE )
726
745
727
746
_symlink_dir (TESTS_ROOT / 'common' / 'ping' , ping_func )
728
- _symlink_dir (EXTENSIONS_PATH , extensions )
747
+ if EXTENSIONS_PATH .exists ():
748
+ _symlink_dir (EXTENSIONS_PATH , extensions )
729
749
730
750
731
751
def _teardown_func_app (app_root ):
0 commit comments