Skip to content

Commit

Permalink
Fix internal error when parametrizing using and empty list of ids()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Aug 23, 2016
1 parent 7538680 commit df20029
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
with normal parameters in the same call (`#1832`_).
Thanks `@The-Compiler`_ for the report, `@Kingdread`_ and `@nicoddemus`_ for the PR.

* Fix internal error when parametrizing tests or fixtures using an empty ``ids`` argument (`#1849`_).
Thanks `@OPpuolitaival`_ for the report and `@nicoddemus`_ for the PR.

* Fix loader error when running ``pytest`` embedded in a zipfile.
Thanks `@mbachry`_ for the PR.

*

*

*

*

.. _@Kingdread: https://github.com/Kingdread
.. _@mbachry: https://github.com/mbachry
.. _@OPpuolitaival: https://github.com/OPpuolitaival

.. _#1822: https://github.com/pytest-dev/pytest/issues/1822
.. _#1832: https://github.com/pytest-dev/pytest/issues/1832
.. _#1849: https://github.com/pytest-dev/pytest/issues/1849


3.0.0
Expand Down
2 changes: 1 addition & 1 deletion _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ def _idval(val, argname, idx, idfn, config=None):
return str(argname)+str(idx)

def _idvalset(idx, valset, argnames, idfn, ids, config=None):
if ids is None or ids[idx] is None:
if ids is None or (idx >= len(ids) or ids[idx] is None):
this_id = [_idval(val, argname, idx, idfn, config)
for val, argname in zip(valset, argnames)]
return "-".join(this_id)
Expand Down
27 changes: 27 additions & 0 deletions testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,33 @@ def test_function(a, b):
"*test_function*advanced*FAILED",
])

def test_fixture_parametrized_empty_ids(self, testdir):
"""Fixtures parametrized with empty ids cause an internal error (#1849)."""
testdir.makepyfile('''
import pytest
@pytest.fixture(scope="module", ids=[], params=[])
def temp(request):
return request.param
def test_temp(temp):
pass
''')
result = testdir.runpytest()
result.stdout.fnmatch_lines(['* 1 skipped *'])

def test_parametrized_empty_ids(self, testdir):
"""Tests parametrized with empty ids cause an internal error (#1849)."""
testdir.makepyfile('''
import pytest
@pytest.mark.parametrize('temp', [], ids=list())
def test_temp(temp):
pass
''')
result = testdir.runpytest()
result.stdout.fnmatch_lines(['* 1 skipped *'])

def test_parametrize_with_identical_ids_get_unique_names(self, testdir):
testdir.makepyfile("""
import pytest
Expand Down

0 comments on commit df20029

Please sign in to comment.