Skip to content

Commit

Permalink
Merge pull request #150 from hirotoKirimaru/main
Browse files Browse the repository at this point in the history
Add short test summary info result message
  • Loading branch information
okken authored Dec 31, 2023
2 parents 61412e6 + 9995682 commit fce78e3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions examples/test_example_short_test_summary_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from pytest_check import check


def test_baseline():
a, b = 1, 2
check.equal(a, b)


def test_message():
a, b = 1, 2
check.equal(a, b, f"comment about a={a} != b={b}")
9 changes: 8 additions & 1 deletion src/pytest_check/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pytest
from _pytest._code.code import ExceptionInfo
from _pytest.skipping import xfailed_key
from _pytest.reports import ExceptionChainRepr
from _pytest._code.code import ExceptionRepr, ReprFileLocation

from . import check_log, check_raises, context_manager, pseudo_traceback

Expand Down Expand Up @@ -36,8 +38,13 @@ def pytest_runtest_makereport(item, call):
report.outcome = "failed"
try:
raise AssertionError(report.longrepr)
except AssertionError:
except AssertionError as e:
excinfo = ExceptionInfo.from_current()
reprcrash = ReprFileLocation(item.nodeid, 0, str(e))
reprtraceback = ExceptionRepr(reprcrash, excinfo)
chain_repr = ExceptionChainRepr([(reprtraceback, reprcrash, str(e))])
report.longrepr = chain_repr

call.excinfo = excinfo


Expand Down
10 changes: 10 additions & 0 deletions tests/test_short_test_summary_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_baseline(pytester):
pytester.copy_example("examples/test_example_short_test_summary_info.py")
result = pytester.runpytest("-k baseline")
result.stdout.fnmatch_lines(["*FAILED*-*FAILURE*"])


def test_message(pytester):
pytester.copy_example("examples/test_example_short_test_summary_info.py")
result = pytester.runpytest("-k message")
result.stdout.fnmatch_lines(["*FAILED*-*FAILURE*"])

0 comments on commit fce78e3

Please sign in to comment.