forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_report_log.py
44 lines (34 loc) · 1.32 KB
/
test_report_log.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import json
import pytest
from _pytest.reports import BaseReport
def test_basics(testdir, tmp_path, pytestconfig):
"""Basic testing of the report log functionality.
We don't test the test reports extensively because they have been
tested already in ``test_reports``.
"""
testdir.makepyfile(
"""
def test_ok():
pass
def test_fail():
assert 0
"""
)
log_file = tmp_path / "log.json"
result = testdir.runpytest("--report-log", str(log_file))
assert result.ret == pytest.ExitCode.TESTS_FAILED
result.stdout.fnmatch_lines(["* generated report log file: {}*".format(log_file)])
json_objs = [json.loads(x) for x in log_file.read_text().splitlines()]
assert len(json_objs) == 9
# first line should be the header
header = json_objs[0]
assert header == {"pytest_version": pytest.__version__, "$report_type": "Header"}
# rest of the json objects should be unserialized into report objects; we don't test
# the actual report object extensively because it has been tested in ``test_reports``
# already.
pm = pytestconfig.pluginmanager
for json_obj in json_objs[1:]:
rep = pm.hook.pytest_report_from_serializable(
config=pytestconfig, data=json_obj
)
assert isinstance(rep, BaseReport)