@@ -299,6 +299,18 @@ def writer(console=mock_rich_console):
299
299
)
300
300
301
301
302
+ @fixture
303
+ def writer_hiding_locals (console = mock_rich_console ):
304
+ yield TestResultWriter (
305
+ console ,
306
+ Suite ([]),
307
+ TestOutputStyle .LIVE ,
308
+ [TestProgressStyle .INLINE ],
309
+ None ,
310
+ show_locals = False ,
311
+ )
312
+
313
+
302
314
for left , right in [
303
315
("abc" , "abd" ),
304
316
(123 , 124 ),
@@ -323,7 +335,7 @@ def _(lhs=left, rhs=right, writer=writer, console=mock_rich_console):
323
335
("a" , {"b" : 1 }),
324
336
]:
325
337
326
- @test ("TestResultWriter.get_operands handles assert `in` failure" )
338
+ @test ("TestResultWriter.get_operands handles assert `in` failure" , tags = [ "aa" ] )
327
339
def _ (lhs = left , rhs = right , writer = writer ):
328
340
failure = TestAssertionFailure ("fail" , lhs , rhs , 1 , Comparison .In , "test" )
329
341
lhs_render , rhs_render = writer .get_operands (failure ).renderables
@@ -398,3 +410,46 @@ def _(console=mock_rich_console):
398
410
result = result_writer .output_all_test_results (_ for _ in ())
399
411
assert result == []
400
412
assert not console .print .called
413
+
414
+
415
+ @test ("TestResultWriter.print_traceback with stacktrace showing locals" )
416
+ def _ (writer = writer ):
417
+ def internal_func3 (** params ):
418
+ return 1 / 0
419
+
420
+ def internal_func2 (name ):
421
+ age = 18
422
+ internal_func3 (name = name , age = age )
423
+
424
+ def internal_func1 ():
425
+ name = "John"
426
+ return internal_func2 (name = name )
427
+
428
+ try :
429
+ internal_func1 ()
430
+ except ZeroDivisionError as ex :
431
+ writer .print_traceback (ex )
432
+
433
+
434
+ @test ("TestResultWriter.print_traceback with stacktrace and hiding locals" )
435
+ def _ (writer = writer_hiding_locals ):
436
+ def internal_func3 (** params ):
437
+ return 1 / 0
438
+
439
+ def internal_func2 (name ):
440
+ age = 18
441
+ internal_func3 (name = name , age = age )
442
+
443
+ def internal_func1 ():
444
+ name = "John"
445
+ return internal_func2 (name = name )
446
+
447
+ try :
448
+ internal_func1 ()
449
+ except ZeroDivisionError as ex :
450
+ writer .print_traceback (ex )
451
+
452
+
453
+ @test ("TestResultWriter.print_traceback without stacktrace" )
454
+ def _ (writer = writer ):
455
+ writer .print_traceback (Exception ("Some error" ))
0 commit comments