@@ -296,20 +296,30 @@ def ids(val):
296296 @pytest .mark .issue351
297297 def test_idmaker_idfn_exception (self ):
298298 from _pytest .python import idmaker
299+ from _pytest .recwarn import WarningsRecorder
299300
300301 class BadIdsException (Exception ):
301302 pass
302303
303304 def ids (val ):
304305 raise BadIdsException ("ids raised" )
305306
306- with pytest .raises (BadIdsException ) as e :
307+ rec = WarningsRecorder ()
308+ with rec :
307309 idmaker (("a" , "b" ), [(10.0 , IndexError ()),
308310 (20 , KeyError ()),
309311 ("three" , [1 , 2 , 3 ]),
310312 ], idfn = ids )
311313
312- assert str (e .value ) == "ids raised"
314+ assert [str (i .message ) for i in rec .list ] == [
315+ "Raised while trying to determine id of parameter a at position 0" ,
316+ "Raised while trying to determine id of parameter b at position 0" ,
317+ "Raised while trying to determine id of parameter a at position 1" ,
318+ "Raised while trying to determine id of parameter b at position 1" ,
319+ "Raised while trying to determine id of parameter a at position 2" ,
320+ "Raised while trying to determine id of parameter b at position 2" ,
321+ ]
322+
313323
314324 def test_parametrize_ids_exception (self , testdir ):
315325 """
@@ -328,9 +338,9 @@ def test_foo(arg):
328338 """ )
329339 result = testdir .runpytest ("--collect-only" )
330340 result .stdout .fnmatch_lines ([
331- "*ERROR collecting test_parametrize_ids_exception.py* " ,
332- "test_parametrize_ids_exception.py:*: in ids " ,
333- "*raise Exception( \" bad ids \" ) " ,
341+ "<Module ' test_parametrize_ids_exception.py'> " ,
342+ " <Function 'test_foo[a]'> " ,
343+ " <Function 'test_foo[b]'> " ,
334344 ])
335345
336346 def test_idmaker_with_ids (self ):
0 commit comments