@@ -195,6 +195,35 @@ def test_suggests_elements_instead_of_annotations():
195
195
class TestErrorNoteBehavior3819 :
196
196
elements = (st .booleans (), st .decimals (), st .integers (), st .text ())
197
197
198
+ @staticmethod
199
+ @given (st .data ())
200
+ def direct_without_error (data ):
201
+ data .draw (st .sampled_from ((st .floats (), st .binary ())))
202
+
203
+ @staticmethod
204
+ @given (st .data ())
205
+ def direct_with_non_type_error (data ):
206
+ data .draw (st .sampled_from (st .characters (), st .floats ()))
207
+ raise Exception ("Contains SearchStrategy, but no note addition!" )
208
+
209
+ @staticmethod
210
+ @given (st .data ())
211
+ def direct_with_type_error_without_substring (data ):
212
+ data .draw (st .sampled_from (st .booleans (), st .binary ()))
213
+ raise TypeError ("Substring not in message!" )
214
+
215
+ @staticmethod
216
+ @given (st .data ())
217
+ def direct_with_type_error_with_substring_but_not_all_strategies (data ):
218
+ data .draw (st .sampled_from (st .booleans (), False , True ))
219
+ raise TypeError ("Contains SearchStrategy, but no note addition!" )
220
+
221
+ @staticmethod
222
+ @given (st .data ())
223
+ def direct_all_strategies_with_type_error_with_substring (data ):
224
+ data .draw (st .sampled_from ((st .dates (), st .datetimes ())))
225
+ raise TypeError ("This message contains SearchStrategy as substring!" )
226
+
198
227
@staticmethod
199
228
@given (st .lists (st .sampled_from (elements )))
200
229
def indirect_without_error (_ ):
@@ -216,9 +245,9 @@ def indirect_with_type_error_with_substring_but_not_all_strategies(_):
216
245
raise TypeError ("Contains SearchStrategy, but no note addition!" )
217
246
218
247
@staticmethod
219
- @given (st .lists (st .sampled_from (elements )))
220
- def indirect_all_strategies_with_type_error_with_substring (_ ):
221
- raise TypeError ("Contains SearchStrategy in message" )
248
+ @given (st .lists (st .sampled_from (elements ), min_size = 1 ))
249
+ def indirect_all_strategies_with_type_error_with_substring (objs ):
250
+ raise TypeError ("Contains SearchStrategy in message, trigger note! " )
222
251
223
252
@pytest .mark .parametrize (
224
253
["func_to_call" , "exp_err_cls" , "should_exp_msg" ],
@@ -227,35 +256,30 @@ def indirect_all_strategies_with_type_error_with_substring(_):
227
256
for f , err , msg_exp in [
228
257
(f , TypeError , True )
229
258
for f in (
230
- args_with_type_error_with_message_substring ,
231
- kwargs_with_type_error_with_message_substring ,
259
+ direct_all_strategies_with_type_error_with_substring ,
232
260
indirect_all_strategies_with_type_error_with_substring ,
233
261
)
234
262
]
235
263
+ [
236
264
(f , TypeError , False )
237
265
for f in (
238
- args_with_type_error_without_message_substring ,
239
- kwargs_with_type_error_without_message_substring ,
240
- type_error_but_not_all_strategies_args ,
241
- type_error_but_not_all_strategies_kwargs ,
266
+ direct_with_type_error_without_substring ,
267
+ direct_with_type_error_with_substring_but_not_all_strategies ,
242
268
indirect_with_type_error_without_substring ,
243
269
indirect_with_type_error_with_substring_but_not_all_strategies ,
244
270
)
245
271
]
246
272
+ [
247
273
(f , Exception , False )
248
274
for f in (
249
- non_type_error_args ,
250
- non_type_error_kwargs ,
275
+ direct_with_non_type_error ,
251
276
indirect_with_non_type_error ,
252
277
)
253
278
]
254
279
+ [
255
280
(f , None , False )
256
281
for f in (
257
- args_without_error ,
258
- kwargs_without_error ,
282
+ direct_without_error ,
259
283
indirect_without_error ,
260
284
)
261
285
]
@@ -272,11 +296,9 @@ def test_error_appropriate_error_note_3819(
272
296
else :
273
297
assert True
274
298
else :
275
- with pytest .raises (Exception ) as err_ctx :
299
+ with pytest .raises (exp_err_cls ) as err_ctx :
276
300
func_to_call ()
277
- err = err_ctx .value
278
- assert type (err ) is exp_err_cls
279
- notes = getattr (err , "__notes__" , [])
301
+ notes = getattr (err_ctx .value , "__notes__" , [])
280
302
msg_in_notes = (
281
303
"sample_from was given a collection of strategies; was one_of intended?"
282
304
in notes
0 commit comments