Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 16a8ebf

Browse files
committed
Cover missing parts of TestResultWriter.print_traceback in tests
1 parent ae729d5 commit 16a8ebf

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

tests/test_terminal.py

+56-1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ def writer(console=mock_rich_console):
299299
)
300300

301301

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+
302314
for left, right in [
303315
("abc", "abd"),
304316
(123, 124),
@@ -323,7 +335,7 @@ def _(lhs=left, rhs=right, writer=writer, console=mock_rich_console):
323335
("a", {"b": 1}),
324336
]:
325337

326-
@test("TestResultWriter.get_operands handles assert `in` failure")
338+
@test("TestResultWriter.get_operands handles assert `in` failure", tags=["aa"])
327339
def _(lhs=left, rhs=right, writer=writer):
328340
failure = TestAssertionFailure("fail", lhs, rhs, 1, Comparison.In, "test")
329341
lhs_render, rhs_render = writer.get_operands(failure).renderables
@@ -398,3 +410,46 @@ def _(console=mock_rich_console):
398410
result = result_writer.output_all_test_results(_ for _ in ())
399411
assert result == []
400412
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

Comments
 (0)