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 f13f175
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion 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 All @@ -323,7 +335,7 @@ def _(lhs=left, rhs=right, writer=writer, console=mock_rich_console):
("a", {"b": 1}),
]:

@test("TestResultWriter.get_operands handles assert `in` failure")
@test("TestResultWriter.get_operands handles assert `in` failure", tags=["aa"])
def _(lhs=left, rhs=right, writer=writer):
failure = TestAssertionFailure("fail", lhs, rhs, 1, Comparison.In, "test")
lhs_render, rhs_render = writer.get_operands(failure).renderables
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 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 without stacktrace")
def _(writer=writer):
writer.print_traceback(Exception("Some error"))

0 comments on commit f13f175

Please sign in to comment.