Skip to content

Commit

Permalink
Cover missing parts of TestResultWriter.print_traceback in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RamonGiovane committed Feb 13, 2023
1 parent ae729d5 commit c97e993
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ def writer(console=mock_rich_console):
)


@fixture
def writer_hiding_locals(console=mock_rich_console):
yield TestResultWriter(
console,
Suite([]),
TestOutputStyle.LIVE,
[TestProgressStyle.INLINE],
None,
show_locals=False,
)


for left, right in [
("abc", "abd"),
(123, 124),
Expand Down Expand Up @@ -398,3 +410,46 @@ def _(console=mock_rich_console):
result = result_writer.output_all_test_results(_ for _ in ())
assert result == []
assert not console.print.called


@test("TestResultWriter.print_traceback with stacktrace showing locals")
def _(writer=writer):
def internal_func3(**params):
return 1 / 0

def internal_func2(name):
age = 18
internal_func3(name=name, age=age)

def internal_func1():
name = "John"
return internal_func2(name=name)

try:
internal_func1()
except ZeroDivisionError as ex:
writer.print_traceback(ex)


@test("TestResultWriter.print_traceback with stacktrace and hiding locals")
def _(writer=writer_hiding_locals):
def internal_func3(**params):
return 1 / 0

def internal_func2(name):
age = 18
internal_func3(name=name, age=age)

def internal_func1():
name = "John"
return internal_func2(name=name)

try:
internal_func1()
except ZeroDivisionError as ex:
writer.print_traceback(ex)


@test("TestResultWriter.print_traceback without stacktrace")
def _(writer=writer):
writer.print_traceback(Exception("Some error"))

0 comments on commit c97e993

Please sign in to comment.