@@ -296,18 +296,58 @@ 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
300+
301+ class BadIdsException(Exception):
302+ pass
299303
300304 def ids(val):
301- raise Exception("bad code")
305+ raise BadIdsException("ids raised")
306+
307+ rec = WarningsRecorder()
308+ with rec:
309+ idmaker(("a", "b"), [(10.0, IndexError()),
310+ (20, KeyError()),
311+ ("three", [1, 2, 3]),
312+ ], idfn=ids)
313+
314+ assert [str(i.message) for i in rec.list] == [
315+ "Raised while trying to determine id of parameter a at position 0."
316+ "\nUpdate your code as this will raise an error in pytest-4.0.",
317+ "Raised while trying to determine id of parameter b at position 0."
318+ "\nUpdate your code as this will raise an error in pytest-4.0.",
319+ "Raised while trying to determine id of parameter a at position 1."
320+ "\nUpdate your code as this will raise an error in pytest-4.0.",
321+ "Raised while trying to determine id of parameter b at position 1."
322+ "\nUpdate your code as this will raise an error in pytest-4.0.",
323+ "Raised while trying to determine id of parameter a at position 2."
324+ "\nUpdate your code as this will raise an error in pytest-4.0.",
325+ "Raised while trying to determine id of parameter b at position 2."
326+ "\nUpdate your code as this will raise an error in pytest-4.0.",
327+ ]
302328
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- ]
329+
330+ def test_parametrize_ids_exception(self, testdir):
331+ """
332+ :param testdir: the instance of Testdir class, a temporary
333+ test directory.
334+ """
335+ testdir.makepyfile("""
336+ import pytest
337+
338+ def ids(arg):
339+ raise Exception("bad ids")
340+
341+ @pytest.mark.parametrize("arg", ["a", "b"], ids=ids)
342+ def test_foo(arg):
343+ pass
344+ """)
345+ result = testdir.runpytest("--collect-only")
346+ result.stdout.fnmatch_lines([
347+ "<Module 'test_parametrize_ids_exception.py'>",
348+ " <Function 'test_foo[a]'>",
349+ " <Function 'test_foo[b]'>",
350+ ])
311351
312352 def test_idmaker_with_ids(self):
313353 from _pytest.python import idmaker
0 commit comments