File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change 5
5
from types import BuiltinFunctionType , FunctionType
6
6
import dataclasses
7
7
import json
8
+ import warnings
8
9
9
10
from hypothesis .strategies import SearchStrategy
10
11
@@ -32,6 +33,14 @@ def to_json_serializable(o):
32
33
if isinstance (o , list ):
33
34
return [to_json_serializable (i ) for i in o ]
34
35
36
+ # Ensure everything is JSON serializable. If this warning is issued, it
37
+ # means the given type needs to be added above if possible.
38
+ try :
39
+ json .dumps (o )
40
+ except TypeError :
41
+ warnings .warn (f"{ o !r} (of type { type (o )} ) is not JSON-serializable. Using the repr instead." )
42
+ return repr (o )
43
+
35
44
return o
36
45
37
46
@mark .optionalhook
@@ -49,9 +58,6 @@ def add_extra_json_metadata(request, json_metadata):
49
58
"""
50
59
def add_metadata (name , obj ):
51
60
obj = to_json_serializable (obj )
52
- # Ensure everything is JSON serializable. If this errors, it means the
53
- # given type needs to be added to to_json_serializable above.
54
- json .dumps (obj )
55
61
json_metadata [name ] = obj
56
62
57
63
test_module = request .module .__name__
You can’t perform that action at this time.
0 commit comments