@@ -203,14 +203,22 @@ def __error_message(self, reason) -> List[str]:
203
203
204
204
message = []
205
205
206
- first_line_test = 3 if self .asynchronous else 2
207
-
208
206
if reason :
209
207
tb = traceback .extract_tb (reason .__traceback__ )
210
208
209
+ first_line_test = 0
210
+
211
+ while first_line_test < len (tb ):
212
+ filename , _ , funcname , _ = tb [first_line_test ]
213
+
214
+ if filename .endswith (str (self .path )) and self .fnc == funcname :
215
+ break
216
+
217
+ first_line_test += 1
218
+
211
219
if len (tb ) > first_line_test :
212
220
# We get the line in the test where the exception has been raised
213
- filename , lineno , funcname , text = tb [first_line_test ]
221
+ filename , lineno , funcname , _ = tb [first_line_test ]
214
222
215
223
message .append (
216
224
f"{ type (reason ).__name__ } in { filename } , line { lineno } , in { funcname } :"
@@ -327,16 +335,16 @@ def failures(
327
335
test_output = [line for line in test .output .getvalue ().split ("\n " )]
328
336
if test_output and not test_output [- 1 ].strip ():
329
337
del test_output [- 1 ]
330
- if test_output :
331
- output .append (" - - - - output:" )
332
- for line in test_output :
333
- output .append (f"{ padding } { line } " )
334
- output .append (" - - - - reason:" )
335
338
if report_failure in (
336
339
ReportFailure .SIMPLE ,
337
340
ReportFailure .NORMAL ,
338
341
ReportFailure .FULL ,
339
342
):
343
+ if test_output :
344
+ output .append (" - - - - output:" )
345
+ for line in test_output :
346
+ output .append (f"{ padding } { line } " )
347
+ output .append (" - - - - reason:" )
340
348
output .append (f"{ padding } { test .reason } " )
341
349
if report_failure in (ReportFailure .NORMAL , ReportFailure .FULL ):
342
350
output .append (f"{ padding } ---------------------" )
0 commit comments