Skip to content

Commit ca2a3d0

Browse files
committed
Fix empty params
1 parent 5c2e9f4 commit ca2a3d0

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

src/_pytest/python.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,13 @@ def _genfunctions(self, name: str, funcobj) -> Iterator[Function]:
475475
fixtureinfo.prune_dependency_tree()
476476

477477
for callspec in metafunc._calls:
478-
params_id = callspec.id
479-
subname = f"{name}[{params_id}]" if params_id else name
478+
subname = f"{name}[{callspec.id}]" if callspec._idlist else name
480479
yield Function.from_parent(
481480
self,
482481
name=subname,
483482
callspec=callspec,
484483
fixtureinfo=fixtureinfo,
485-
keywords={params_id: True},
484+
keywords={callspec.id: True},
486485
originalname=name,
487486
)
488487

@@ -1086,7 +1085,7 @@ def setmulti(
10861085
params=params,
10871086
indices=indices,
10881087
_arg2scope=arg2scope,
1089-
_idlist=[*self._idlist, id] if id else self._idlist,
1088+
_idlist=[*self._idlist, id] if id is not None else self._idlist,
10901089
marks=[*self.marks, *normalize_mark_list(marks)],
10911090
)
10921091

testing/python/metafunc.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,7 @@ class TestHiddenParam:
21492149
"""Test that pytest.HIDDEN_PARAM works"""
21502150

21512151
def test_parametrize_ids(self, pytester: Pytester) -> None:
2152-
pytester.makepyfile(
2152+
items = pytester.getitems(
21532153
"""
21542154
import pytest
21552155
@@ -2166,18 +2166,15 @@ def test_func(foo, bar):
21662166
pass
21672167
"""
21682168
)
2169-
result = pytester.runpytest("-vv", "-s")
2170-
result.stdout.fnmatch_lines(
2171-
[
2172-
"test_parametrize_ids.py::test_func[paramset1] PASSED",
2173-
"test_parametrize_ids.py::test_func PASSED",
2174-
"test_parametrize_ids.py::test_func[paramset3] PASSED",
2175-
"*= 3 passed in *",
2176-
]
2177-
)
2169+
names = [item.name for item in items]
2170+
assert names == [
2171+
"test_func[paramset1]",
2172+
"test_func",
2173+
"test_func[paramset3]",
2174+
]
21782175

21792176
def test_param_id(self, pytester: Pytester) -> None:
2180-
pytester.makepyfile(
2177+
items = pytester.getitems(
21812178
"""
21822179
import pytest
21832180
@@ -2193,15 +2190,12 @@ def test_func(foo, bar):
21932190
pass
21942191
"""
21952192
)
2196-
result = pytester.runpytest("-vv", "-s")
2197-
result.stdout.fnmatch_lines(
2198-
[
2199-
"test_param_id.py::test_func[paramset1] PASSED",
2200-
"test_param_id.py::test_func PASSED",
2201-
"test_param_id.py::test_func[c-z] PASSED",
2202-
"*= 3 passed in *",
2203-
]
2204-
)
2193+
names = [item.name for item in items]
2194+
assert names == [
2195+
"test_func[paramset1]",
2196+
"test_func",
2197+
"test_func[c-z]",
2198+
]
22052199

22062200
def test_multiple_hidden_param_is_forbidden(self, pytester: Pytester) -> None:
22072201
pytester.makepyfile(
@@ -2235,7 +2229,7 @@ def test_func(foo, bar):
22352229
)
22362230

22372231
def test_multiple_parametrize(self, pytester: Pytester) -> None:
2238-
pytester.makepyfile(
2232+
items = pytester.getitems(
22392233
"""
22402234
import pytest
22412235
@@ -2252,13 +2246,10 @@ def test_func(foo, bar):
22522246
pass
22532247
"""
22542248
)
2255-
result = pytester.runpytest("-vv", "-s")
2256-
result.stdout.fnmatch_lines(
2257-
[
2258-
"test_multiple_parametrize.py::test_func[a-x] PASSED",
2259-
"test_multiple_parametrize.py::test_func[a-y] PASSED",
2260-
"test_multiple_parametrize.py::test_func[x] PASSED",
2261-
"test_multiple_parametrize.py::test_func[y] PASSED",
2262-
"*= 4 passed in *",
2263-
]
2264-
)
2249+
names = [item.name for item in items]
2250+
assert names == [
2251+
"test_func[a-x]",
2252+
"test_func[a-y]",
2253+
"test_func[x]",
2254+
"test_func[y]",
2255+
]

0 commit comments

Comments
 (0)