Skip to content

Commit 377f3e6

Browse files
committed
show assertion error by default
1 parent cf8dcdf commit 377f3e6

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pytest-elegant"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
description = "A pytest plugin that provides elegant, beautiful test output"
55
readme = "README.md"
66
authors = [

src/pytest_elegant/reporter.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,12 @@ def _print_failure_details(self, report: TestReport) -> None:
629629
lines = longrepr_str.split("\n")
630630

631631
# Extract the main error message and location
632-
# Skip verbose diff output, "Differing items:", "use `-vv`" messages, etc.
633632
error_message = None
634633
error_type = None
635634
file_location = None
636635
file_path = None
637636
line_number = None
637+
introspection_lines: list[str] = []
638638

639639
import re
640640

@@ -657,32 +657,37 @@ def _print_failure_details(self, report: TestReport) -> None:
657657
except (ValueError, IndexError):
658658
pass
659659

660-
# Get the first meaningful error message (E line with error info)
661-
if error_message is None and stripped.startswith("E "):
660+
if stripped.startswith("E "):
662661
error_content = stripped[2:].strip()
663662

664-
# Match "SomeName: message" where SomeName has no spaces (exception class)
665-
if ": " in error_content:
666-
before_colon = error_content.split(": ", 1)[0]
667-
if " " not in before_colon and before_colon:
668-
error_message = error_content.split(": ", 1)[1]
669-
# Extract error type from the class name (last component)
670-
error_type = before_colon.split(".")[-1]
671-
# Skip verbose assertion rewrites with diffs
672-
elif error_content.startswith("assert ") and not ('{' in error_content and '...' in error_content):
673-
error_message = error_content
663+
# Skip pytest hints about verbosity
664+
if "use -v" in error_content.lower():
665+
continue
666+
667+
if error_message is None:
668+
# Match "SomeName: message" where SomeName has no spaces (exception class)
669+
if ": " in error_content:
670+
before_colon = error_content.split(": ", 1)[0]
671+
if " " not in before_colon and before_colon:
672+
error_message = error_content.split(": ", 1)[1]
673+
# Extract error type from the class name (last component)
674+
error_type = before_colon.split(".")[-1]
675+
676+
if error_message is None and error_content.startswith("assert "):
677+
error_message = error_content
678+
elif error_content:
679+
# Subsequent E lines are assertion introspection details
680+
introspection_lines.append(error_content)
674681

675682
# If we still don't have an error message, create one from error type
676683
if error_message is None and error_type:
677684
error_message = f"{error_type} occurred."
678685

679686
# Display the error with elegant formatting
680687
if error_message:
681-
# Clean up assertion messages with verbose comparisons
682-
if "assert" in error_message.lower() and "==" in error_message:
683-
error_message = "Failed asserting that values are equal."
684-
685688
self.write_line(f" {error_message}", red=True)
689+
for intro_line in introspection_lines:
690+
self.write_line(f" {intro_line}")
686691

687692
# Show file location if available
688693
if file_location:

0 commit comments

Comments
 (0)