Skip to content

Commit 668cdf7

Browse files
committed
Fix subtests jsonl report to be consistent with other reports
Fix #90
1 parent 986dbfb commit 668cdf7

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎CHANGELOG.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
UNRELEASED
22
----------
33

4+
* `#90 <https://github.com/pytest-dev/pytest-reportlog/issues/90>`_: Fix jsonl output for pytest subtests (introduced in pytest 9.0).
45
* Added official support for Python 3.12 and 3.13.
56
* Dropped support for EOL Python 3.7 and Python 3.8.
67

‎src/pytest_reportlog/plugin.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def pytest_runtest_logreport(self, report):
8989
data = self._config.hook.pytest_report_to_serializable(
9090
config=self._config, report=report
9191
)
92+
93+
# Workaround for subtests that output `_report_type` instead of `$report_type` (#90).
94+
if "_report_type" in data:
95+
data["$report_type"] = data.pop("_report_type")
96+
9297
if (
9398
self._config.option.report_log_exclude_logs_on_passed_tests
9499
and data.get("outcome", "") == "passed"

‎tests/test_reportlog.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,21 @@ def __str__(self):
186186
bad = {"x": 1, "y": ["a", "b"], "c": C()}
187187
new = cleanup_unserializable(bad)
188188
assert new == {"x": 1, "c": "C instance", "y": ["a", "b"]}
189+
190+
191+
def test_subtest(pytester, tmp_path):
192+
"""Regression test for #90."""
193+
pytester.makepyfile(
194+
"""
195+
def test_foo(subtests):
196+
with subtests.test():
197+
pass
198+
"""
199+
)
200+
fn = tmp_path / "result.log"
201+
result = pytester.runpytest(f"--report-log={fn}")
202+
result.stdout.fnmatch_lines("*1 passed in*")
203+
lines = fn.read_text("UTF-8").splitlines()
204+
for line in lines:
205+
data = json.loads(line)
206+
assert "$report_type" in data

0 commit comments

Comments
 (0)