|
3 | 3 | import pytest
|
4 | 4 | from _pytest.reports import BaseReport
|
5 | 5 |
|
| 6 | +from pytest_reportlog.plugin import cleanup_unserializable |
| 7 | + |
6 | 8 |
|
7 | 9 | def test_basics(testdir, tmp_path, pytestconfig):
|
8 | 10 | """Basic testing of the report log functionality.
|
@@ -52,3 +54,41 @@ def test_fail():
|
52 | 54 | config=pytestconfig, data=json_obj
|
53 | 55 | )
|
54 | 56 | assert isinstance(rep, BaseReport)
|
| 57 | + |
| 58 | + |
| 59 | +def test_xdist_integration(testdir, tmp_path): |
| 60 | + pytest.importorskip("xdist") |
| 61 | + testdir.makepyfile( |
| 62 | + """ |
| 63 | + def test_ok(): |
| 64 | + pass |
| 65 | +
|
| 66 | + def test_fail(): |
| 67 | + assert 0 |
| 68 | + """ |
| 69 | + ) |
| 70 | + fn = tmp_path / "result.log" |
| 71 | + result = testdir.runpytest("-n2", "--report-log={}".format(fn)) |
| 72 | + result.stdout.fnmatch_lines("*1 failed, 1 passed*") |
| 73 | + |
| 74 | + lines = fn.read_text("UTF-8").splitlines() |
| 75 | + data = json.loads(lines[0]) |
| 76 | + assert data == { |
| 77 | + "pytest_version": pytest.__version__, |
| 78 | + "$report_type": "SessionStart", |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | +def test_cleanup_unserializable(): |
| 83 | + """Unittest for the cleanup_unserializable function""" |
| 84 | + good = {"x": 1, "y": ["a", "b"]} |
| 85 | + new = cleanup_unserializable(good) |
| 86 | + assert new == good |
| 87 | + |
| 88 | + class C: |
| 89 | + def __str__(self): |
| 90 | + return "C instance" |
| 91 | + |
| 92 | + bad = {"x": 1, "y": ["a", "b"], "c": C()} |
| 93 | + new = cleanup_unserializable(bad) |
| 94 | + assert new == {"x": 1, "c": "C instance", "y": ["a", "b"]} |
0 commit comments