Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix internal error when parametrizing using and empty list of ids() #1855

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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