File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 1111from contextlib import ExitStack
1212from contextlib import nullcontext
1313import dataclasses
14+ import json
1415import time
1516from types import TracebackType
1617from typing import Any
@@ -63,8 +64,15 @@ class SubtestContext:
6364
6465 def _to_json (self ) -> dict [str , Any ]:
6566 result = dataclasses .asdict (self )
66- # Brute-force the returned kwargs dict to be JSON serializable (pytest-dev/pytest-xdist#1273).
67- result ["kwargs" ] = {k : saferepr (v ) for (k , v ) in result ["kwargs" ].items ()}
67+
68+ # Best-effort to convert the kwargs values to JSON (pytest-dev/pytest-xdist#1273).
69+ def convert (x : Any ) -> str :
70+ try :
71+ return json .dumps (x )
72+ except TypeError :
73+ return saferepr (x )
74+
75+ result ["kwargs" ] = {k : convert (v ) for (k , v ) in result ["kwargs" ].items ()}
6876 return result
6977
7078 @classmethod
You can’t perform that action at this time.
0 commit comments