Skip to content

Commit

Permalink
Merge branch 'mr/pmderodat/xunit-importer' into 'master'
Browse files Browse the repository at this point in the history
e3-convert-xunit: truncate too long test result messages

See merge request it/e3-testsuite!31
  • Loading branch information
pmderodat committed Jul 10, 2024
2 parents 9f7dbd9 + 96156bd commit 4331aab
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
27.0 (Not released yet)
=======================

* `e3-convert-xunit`: truncate too long test result messages.
* `e3-convert-xunit`: warn about dangling XFAILs annotations.
* `DiffTestDriver`: tolerate missing baseline files when rewriting baselines.
* The `--xunit-name` argument of `e3-testsuite-report` is now used to
Expand Down
16 changes: 16 additions & 0 deletions src/e3/testsuite/report/xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ def run(self, filename: str) -> None:
result.log += status_elt.text

message = status_elt.attrib.get("message")

# Some XUnit producers are know to put full logs in the
# "message" attribute, which produces unexpected results in
# e3-testsuite report viewers. Keep the first line only,
# and cap its length if needed.
capped = False
if message is not None:
if "\n" in message:
message = message.split("\n", 1)[0]
capped = True
if len(message) > 200:
message = message[:200]
capped = True
if capped:
message = message.strip() + " [...]"

else:
message = None

Expand Down
39 changes: 39 additions & 0 deletions tests/tests/test_xunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ def test_import(tmp_path, capsys):
<testcase name="test_name" classname="MyClass">
</testcase>
<!-- Test handling of multiline messages. -->
<testcase name="test-failure-multiline-message">
<failure message="Some multi&#10;
line&#10;
message...">\
Some failure logging</failure>
</testcase>
<!-- Test handling of too long messages. -->
<testcase name="test-failure-too-long-message">
<failure message="Some extremely very ultra long
message. Viewers may not like it, so we are going to strip it to ~200 colons.
The imported report will include only a small prefix of this too long message.
They will not see the complete message. This is okay, as in known cases where
messages are too long, their content is actually also present in the log, which
is not capped, so no content is lost in practice.
">Some failure logging</failure>
</testcase>
</testsuite>
<!-- Test usage of XFAILs. -->
Expand Down Expand Up @@ -266,6 +285,8 @@ def test_import(tmp_path, capsys):
"Normal.test-error",
"Normal.test-failure",
"Normal.test-failure-message",
"Normal.test-failure-multiline-message",
"Normal.test-failure-too-long-message",
"Normal.test-skipped",
"Normal.test1",
"XFails.pytest-skip",
Expand Down Expand Up @@ -298,6 +319,24 @@ def check_log(test_name, log):
check("Normal.test-failure", Status.FAIL)
check_log("Normal.test-failure", "Some failure logging")

check(
"Normal.test-failure-multiline-message",
Status.FAIL,
message="Some multi [...]",
)
check_log("Normal.test-failure-multiline-message", "Some failure logging")
check(
"Normal.test-failure-too-long-message",
Status.FAIL,
message=(
"Some extremely very ultra long message. Viewers may not like it,"
" so we are going to strip it to ~200 colons. The imported report"
" will include only a small prefix of this too long message. They"
" will no [...]"
),
)
check_log("Normal.test-failure-too-long-message", "Some failure logging")

check("Normal.test-error", Status.ERROR)
check_log("Normal.test-error", "Some error logging")

Expand Down

0 comments on commit 4331aab

Please sign in to comment.