|
3 | 3 | import sys |
4 | 4 | from typing import Literal |
5 | 5 |
|
| 6 | +from _pytest.subtests import SubtestContext |
| 7 | +from _pytest.subtests import SubtestReport |
6 | 8 | import pytest |
7 | 9 |
|
8 | 10 |
|
@@ -642,9 +644,10 @@ def test(subtests): |
642 | 644 | """ |
643 | 645 | ) |
644 | 646 |
|
645 | | - def test_capturing(self, pytester: pytest.Pytester) -> None: |
| 647 | + @pytest.mark.parametrize("mode", ["fd", "sys"]) |
| 648 | + def test_capturing(self, pytester: pytest.Pytester, mode: str) -> None: |
646 | 649 | self.create_file(pytester) |
647 | | - result = pytester.runpytest() |
| 650 | + result = pytester.runpytest(f"--capture={mode}") |
648 | 651 | result.stdout.fnmatch_lines( |
649 | 652 | [ |
650 | 653 | "*__ test (i='A') __*", |
@@ -952,3 +955,23 @@ def test(subtests): |
952 | 955 | "* 3 failed in *", |
953 | 956 | ] |
954 | 957 | ) |
| 958 | + |
| 959 | + |
| 960 | +def test_serialization() -> None: |
| 961 | + from _pytest.subtests import pytest_report_from_serializable |
| 962 | + from _pytest.subtests import pytest_report_to_serializable |
| 963 | + |
| 964 | + report = SubtestReport( |
| 965 | + "test_foo::test_foo", |
| 966 | + ("test_foo.py", 12, ""), |
| 967 | + keywords={}, |
| 968 | + outcome="passed", |
| 969 | + when="call", |
| 970 | + longrepr=None, |
| 971 | + context=SubtestContext(msg="custom message", kwargs=dict(i=10)), |
| 972 | + ) |
| 973 | + data = pytest_report_to_serializable(report) |
| 974 | + assert data is not None |
| 975 | + new_report = pytest_report_from_serializable(data) |
| 976 | + assert new_report is not None |
| 977 | + assert new_report.context == SubtestContext(msg="custom message", kwargs=dict(i=10)) |
0 commit comments