Skip to content

Commit c840502

Browse files
Merge pull request #46 from codecov/joseph/null-duration
feat: make duration_seconds optional
2 parents 02db067 + 2443547 commit c840502

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

src/junit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ fn populate(
6363
.time
6464
.as_deref()
6565
.or(testsuite_time)
66-
.ok_or_else(|| ParserError::new_err("No time/duration found"))?
67-
.parse()?;
66+
.and_then(|t| t.parse().ok());
6867

6968
let mut t = Testrun {
7069
name,

src/testrun.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct Testrun {
8585
#[pyo3(get, set)]
8686
pub classname: String,
8787
#[pyo3(get, set)]
88-
pub duration: f64,
88+
pub duration: Option<f64>,
8989
#[pyo3(get, set)]
9090
pub outcome: Outcome,
9191
#[pyo3(get, set)]
@@ -139,7 +139,7 @@ impl Testrun {
139139
fn new(
140140
name: String,
141141
classname: String,
142-
duration: f64,
142+
duration: Option<f64>,
143143
outcome: Outcome,
144144
testsuite: String,
145145
failure_message: Option<String>,
@@ -162,7 +162,7 @@ impl Testrun {
162162

163163
fn __repr__(&self) -> String {
164164
format!(
165-
"({}, {}, {}, {}, {}, {:?}, {:?}, {:?})",
165+
"({}, {}, {}, {:?}, {}, {:?}, {:?}, {:?})",
166166
self.name,
167167
self.classname,
168168
self.outcome,
@@ -276,7 +276,7 @@ mod tests {
276276
let t = Testrun {
277277
classname: "".to_string(),
278278
name: "".to_string(),
279-
duration: 0.0,
279+
duration: None,
280280
outcome: Outcome::Pass,
281281
testsuite: "pytest".to_string(),
282282
failure_message: None,
@@ -292,7 +292,7 @@ mod tests {
292292
let t = Testrun {
293293
classname: "".to_string(),
294294
name: "".to_string(),
295-
duration: 0.0,
295+
duration: None,
296296
outcome: Outcome::Pass,
297297
testsuite: "".to_string(),
298298
failure_message: None,
@@ -308,7 +308,7 @@ mod tests {
308308
let t = Testrun {
309309
classname: ".py".to_string(),
310310
name: "".to_string(),
311-
duration: 0.0,
311+
duration: None,
312312
outcome: Outcome::Pass,
313313
testsuite: "".to_string(),
314314
failure_message: None,
@@ -324,7 +324,7 @@ mod tests {
324324
let t = Testrun {
325325
classname: "".to_string(),
326326
name: ".py".to_string(),
327-
duration: 0.0,
327+
duration: None,
328328
outcome: Outcome::Pass,
329329
testsuite: "".to_string(),
330330
failure_message: None,
@@ -340,7 +340,7 @@ mod tests {
340340
let t = Testrun {
341341
classname: "".to_string(),
342342
name: "".to_string(),
343-
duration: 0.0,
343+
duration: None,
344344
outcome: Outcome::Pass,
345345
testsuite: "".to_string(),
346346
failure_message: Some(".py".to_string()),
@@ -356,7 +356,7 @@ mod tests {
356356
let t = Testrun {
357357
classname: "".to_string(),
358358
name: "".to_string(),
359-
duration: 0.0,
359+
duration: None,
360360
outcome: Outcome::Pass,
361361
testsuite: "".to_string(),
362362
failure_message: Some(".py".to_string()),

tests/no-time.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuites>
3+
<testsuite name="/file1.xml" tests="2"
4+
assertions="2" errors="0" failures="0" skipped="0">
5+
<testsuite name="Thing"
6+
file="/file1.php"
7+
tests="2" assertions="2" errors="0" failures="0" skipped="0">
8+
<testcase
9+
name="test1"
10+
file="/file1.php"
11+
line="1"
12+
classname="class.className" assertions="1"
13+
/>
14+
<testcase
15+
name="test2"
16+
file="/file1.php"
17+
line="2"
18+
assertions="1"
19+
/>
20+
</testsuite>
21+
</testsuite>
22+
</testsuites>

tests/test_junit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,13 @@ def test_junit(self, filename, expected, check):
276276
],
277277
),
278278
),
279+
(
280+
"./tests/testsuites.xml",
281+
ParsingInfo(
282+
None,
283+
[],
284+
),
285+
),
279286
],
280287
)
281288
def test_junit(self, filename, expected):

tests/testsuites.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<testsuites name="empty_testsuites" tests="0" failures="0" />

0 commit comments

Comments
 (0)