Bug 1704142 - [mozlog] Handle duration in errorsummary formatter when no 'test_end' is found, r=marco

Differential Revision: https://phabricator.services.mozilla.com/D111468
This commit is contained in:
Andrew Halberstadt 2021-04-15 14:18:03 +00:00
Родитель 085b2502ff
Коммит 85ddfb695e
2 изменённых файлов: 46 добавлений и 15 удалений

Просмотреть файл

@ -67,17 +67,25 @@ class ErrorSummaryFormatter(BaseFormatter):
return self._output("test_groups", {"groups": list(item["tests"].keys())})
def suite_end(self, data):
return "".join(
self._output(
"group_result",
{
"group": group,
"status": info["status"],
"duration": info["end"] - info["start"],
},
output = []
for group, info in self.groups.items():
if info["start"] is None or info["end"] is None:
duration = None
else:
duration = info["end"] - info["start"]
output.append(
self._output(
"group_result",
{
"group": group,
"status": info["status"],
"duration": duration,
},
)
)
for group, info in self.groups.items()
)
return "".join(output)
def test_start(self, item):
group = self.test_to_group.get(item["test"], None)

Просмотреть файл

@ -2,7 +2,6 @@
import json
import time
from textwrap import dedent
import mozunit
import pytest
@ -32,16 +31,40 @@ import pytest
("test_end", "test_baz", "PASS", "FAIL"),
("suite_end",),
],
dedent(
"""
"""
{"groups": ["manifestA", "manifestB"], "action": "test_groups", "line": 0}
{"test": "test_baz", "subtest": null, "group": "manifestA", "status": "PASS", "expected": "FAIL", "message": null, "stack": null, "known_intermittent": [], "action": "test_result", "line": 8}
{"group": "manifestA", "status": "ERROR", "duration": 70, "action": "group_result", "line": 9}
{"group": "manifestB", "status": "OK", "duration": 10, "action": "group_result", "line": 9}
"""
).lstrip("\n"),
""".strip(),
id="basic",
),
pytest.param(
[
("suite_start", {"manifest": ["test_foo"]}),
("test_start", "test_foo"),
("suite_end",),
],
"""
{"groups": ["manifest"], "action": "test_groups", "line": 0}
{"group": "manifest", "status": null, "duration": null, "action": "group_result", "line": 2}
""".strip(),
id="missing_test_end",
),
pytest.param(
[
("suite_start", {"manifest": ["test_foo"]}),
("test_start", "test_foo"),
("test_status", "test_foo", "subtest", "PASS"),
("suite_end",),
],
"""
{"groups": ["manifest"], "action": "test_groups", "line": 0}
{"group": "manifest", "status": "ERROR", "duration": null, "action": "group_result", "line": 3}
""".strip(),
id="missing_test_end_with_test_status_ok",
marks=pytest.mark.xfail, # status is OK but should be ERROR
),
),
)
def test_errorsummary(monkeypatch, get_logger, logs, expected):