@@ -123,8 +123,10 @@ def test_1(self, item):
123123 expected_params = [1 , 2 , 3 , 4 , [1 , 2 , 3 ]]
124124 assert len (spans ) == 5
125125 for i in range (len (expected_params )):
126- extracted_params = json .loads (spans [i ].meta [test .PARAMETERS ])
127- assert extracted_params == {"arguments" : {"item" : expected_params [i ]}, "metadata" : {}}
126+ assert json .loads (spans [i ].meta [test .PARAMETERS ]) == {
127+ "arguments" : {"item" : str (expected_params [i ])},
128+ "metadata" : {},
129+ }
128130
129131 def test_parameterize_case_complex_objects (self ):
130132 """Test parametrize case with complex objects."""
@@ -153,6 +155,7 @@ def item_param():
153155 pytest.param({"a": A("test_name", "value"), "b": [1, 2, 3]}, marks=pytest.mark.skip),
154156 pytest.param(MagicMock(value=MagicMock()), marks=pytest.mark.skip),
155157 pytest.param(circular_reference, marks=pytest.mark.skip),
158+ pytest.param({("x", "y"): 12345}, marks=pytest.mark.skip),
156159 ]
157160 )
158161 class Test1(object):
@@ -162,7 +165,7 @@ def test_1(self, item):
162165 )
163166 file_name = os .path .basename (py_file .strpath )
164167 rec = self .inline_run ("--ddtrace" , file_name )
165- rec .assertoutcome (skipped = 6 )
168+ rec .assertoutcome (skipped = 7 )
166169 spans = self .pop_spans ()
167170
168171 # Since object will have arbitrary addresses, only need to ensure that
@@ -171,14 +174,40 @@ def test_1(self, item):
171174 "test_parameterize_case_complex_objects.A" ,
172175 "test_parameterize_case_complex_objects.A" ,
173176 "<function item_param at 0x" ,
174- '"a": " <test_parameterize_case_complex_objects.A' ,
177+ "'a': <test_parameterize_case_complex_objects.A" ,
175178 "<MagicMock id=" ,
176179 "test_parameterize_case_complex_objects.A" ,
180+ "{('x', 'y'): 12345}" ,
177181 ]
178- assert len (spans ) == 6
182+ assert len (spans ) == 7
179183 for i in range (len (expected_params_contains )):
180184 assert expected_params_contains [i ] in spans [i ].meta [test .PARAMETERS ]
181185
186+ def test_parameterize_case_encoding_error (self ):
187+ """Test parametrize case with complex objects that cannot be JSON encoded."""
188+ py_file = self .testdir .makepyfile (
189+ """
190+ from mock import MagicMock
191+ import pytest
192+
193+ class A:
194+ def __repr__(self):
195+ raise Exception("Cannot __repr__")
196+
197+ @pytest.mark.parametrize('item',[A()])
198+ class Test1(object):
199+ def test_1(self, item):
200+ assert True
201+ """
202+ )
203+ file_name = os .path .basename (py_file .strpath )
204+ rec = self .inline_run ("--ddtrace" , file_name )
205+ rec .assertoutcome (passed = 1 )
206+ spans = self .pop_spans ()
207+
208+ assert len (spans ) == 1
209+ assert json .loads (spans [0 ].meta [test .PARAMETERS ]) == {"arguments" : {"item" : "Could not encode" }, "metadata" : {}}
210+
182211 def test_skip (self ):
183212 """Test parametrize case."""
184213 py_file = self .testdir .makepyfile (
0 commit comments