@@ -297,17 +297,41 @@ def ids(val):
297297 def test_idmaker_idfn_exception (self ):
298298 from _pytest .python import idmaker
299299
300+ class BadIdsException (Exception ):
301+ pass
302+
300303 def ids (val ):
301- raise Exception ( "bad code " )
304+ raise BadIdsException ( "ids raised " )
302305
303- result = idmaker (("a" , "b" ), [(10.0 , IndexError ()),
304- (20 , KeyError ()),
305- ("three" , [1 , 2 , 3 ]),
306- ], idfn = ids )
307- assert result == ["10.0-b0" ,
308- "20-b1" ,
309- "three-b2" ,
310- ]
306+ with pytest .raises (BadIdsException ) as e :
307+ idmaker (("a" , "b" ), [(10.0 , IndexError ()),
308+ (20 , KeyError ()),
309+ ("three" , [1 , 2 , 3 ]),
310+ ], idfn = ids )
311+
312+ assert str (e .value ) == "ids raised"
313+
314+ def test_parametrize_ids_exception (self , testdir ):
315+ """
316+ :param testdir: the instance of Testdir class, a temporary
317+ test directory.
318+ """
319+ testdir .makepyfile ("""
320+ import pytest
321+
322+ def ids(arg):
323+ raise Exception("bad ids")
324+
325+ @pytest.mark.parametrize("arg", ["a", "b"], ids=ids)
326+ def test_foo(arg):
327+ pass
328+ """ )
329+ result = testdir .runpytest ("--collect-only" )
330+ 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\" )" ,
334+ ])
311335
312336 def test_idmaker_with_ids (self ):
313337 from _pytest .python import idmaker
0 commit comments