Skip to content

Commit 3c866e7

Browse files
authored
Merge pull request #1855 from nicoddemus/fix-empty-parametrize-ids
Fix internal error when parametrizing using and empty list of ids()
2 parents 7538680 + df20029 commit 3c866e7

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@
88
with normal parameters in the same call (`#1832`_).
99
Thanks `@The-Compiler`_ for the report, `@Kingdread`_ and `@nicoddemus`_ for the PR.
1010

11+
* Fix internal error when parametrizing tests or fixtures using an empty ``ids`` argument (`#1849`_).
12+
Thanks `@OPpuolitaival`_ for the report and `@nicoddemus`_ for the PR.
13+
1114
* Fix loader error when running ``pytest`` embedded in a zipfile.
1215
Thanks `@mbachry`_ for the PR.
1316

1417
*
1518

16-
*
1719

1820
*
1921

2022
*
2123

2224
.. _@Kingdread: https://github.com/Kingdread
2325
.. _@mbachry: https://github.com/mbachry
26+
.. _@OPpuolitaival: https://github.com/OPpuolitaival
2427

2528
.. _#1822: https://github.com/pytest-dev/pytest/issues/1822
2629
.. _#1832: https://github.com/pytest-dev/pytest/issues/1832
30+
.. _#1849: https://github.com/pytest-dev/pytest/issues/1849
2731

2832

2933
3.0.0

_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ def _idval(val, argname, idx, idfn, config=None):
936936
return str(argname)+str(idx)
937937

938938
def _idvalset(idx, valset, argnames, idfn, ids, config=None):
939-
if ids is None or ids[idx] is None:
939+
if ids is None or (idx >= len(ids) or ids[idx] is None):
940940
this_id = [_idval(val, argname, idx, idfn, config)
941941
for val, argname in zip(valset, argnames)]
942942
return "-".join(this_id)

testing/python/metafunc.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,33 @@ def test_function(a, b):
889889
"*test_function*advanced*FAILED",
890890
])
891891

892+
def test_fixture_parametrized_empty_ids(self, testdir):
893+
"""Fixtures parametrized with empty ids cause an internal error (#1849)."""
894+
testdir.makepyfile('''
895+
import pytest
896+
897+
@pytest.fixture(scope="module", ids=[], params=[])
898+
def temp(request):
899+
return request.param
900+
901+
def test_temp(temp):
902+
pass
903+
''')
904+
result = testdir.runpytest()
905+
result.stdout.fnmatch_lines(['* 1 skipped *'])
906+
907+
def test_parametrized_empty_ids(self, testdir):
908+
"""Tests parametrized with empty ids cause an internal error (#1849)."""
909+
testdir.makepyfile('''
910+
import pytest
911+
912+
@pytest.mark.parametrize('temp', [], ids=list())
913+
def test_temp(temp):
914+
pass
915+
''')
916+
result = testdir.runpytest()
917+
result.stdout.fnmatch_lines(['* 1 skipped *'])
918+
892919
def test_parametrize_with_identical_ids_get_unique_names(self, testdir):
893920
testdir.makepyfile("""
894921
import pytest

0 commit comments

Comments
 (0)