Skip to content

Commit

Permalink
Merge pull request #10 from codecov/joseph/failure-message-attr
Browse files Browse the repository at this point in the history
fix: handle case where failure test is empty and message is in attribute
  • Loading branch information
joseph-sentry authored Apr 3, 2024
2 parents 95e1d4b + dfbc243 commit 55a5e51
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub fn parse_junit_xml(file_bytes: Vec<u8>) -> PyResult<Vec<Testrun>> {
let mut testrun = saved_testrun
.ok_or(ParserError::new_err("Error accessing saved testrun"))?;
testrun.outcome = Outcome::Failure;
let attr_hm = attributes_map(e.attributes())?;
let tentative_message = attr_hm.get("message").cloned();
testrun.failure_message = tentative_message;
saved_testrun = Some(testrun);
in_failure = true;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/empty_failure.junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
<testsuites tests="2" failures="1" errors="0" skipped="0" time="1.234">
<testsuite name="test" tests="2" errors="0" failures="0" skipped="0" time="1.234">
<testcase classname="test.test"
name="test.test works"
file="./test.rb" time="0.234" />
</testsuite>
<testcase classname="test.test"
name="test.test fails"
file="./test.rb" time="1.000">
<failure message="TestError"
type="TestError">
</failure>
</testcase>
</testsuites>
20 changes: 20 additions & 0 deletions tests/test_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,25 @@ def test_junit(self, filename, expected, check):
),
],
),
(
"./tests/empty_failure.junit.xml",
[
Testrun(
"test.test::test.test works",
0.234,
Outcome.Pass,
"test",
None
),
Testrun(
"test.test::test.test fails",
1,
Outcome.Failure,
"test",
"TestError"
),
]
),
],
)
def test_junit(self, filename, expected):
Expand All @@ -101,3 +120,4 @@ def test_junit(self, filename, expected):
assert len(res) == len(expected)
for restest, extest in zip(res, expected):
assert restest == extest

0 comments on commit 55a5e51

Please sign in to comment.