pytest-dev/pytest · error · CollectError
Empty parameter set in
Error message
Empty parameter set in '{func.__name__}' at line {lineno + 1} What it means
A Collector.CollectError raised when a parametrize call yields an empty parameter set and the ini option empty_parameter_set_mark is set to 'fail_at_collect'. By default pytest skips such tests; only this explicit configuration turns the empty set into a hard collection failure. The function name and 1-based line number are included so the user can locate the offending parametrize.
Solutions
- Supply at least one parameter row, or guard the parametrize call so it is only applied when data exists.
- Change the ini option to 'skip' (default) or 'xfail' if an empty set is legitimate.
- If the emptiness is a bug, fix the upstream data source / generator so it yields the expected rows.
Example fix
# before
@pytest.mark.parametrize('a', [])
def test_x(a): ...
# after
@pytest.mark.parametrize('a', [1])
def test_x(a): ... Defensive patterns
Strategy: validation
Validate before calling
def has_params(param_values) -> bool:
return len(list(param_values)) > 0 Try / catch
import pytest
try:
# collection happens here
...
except pytest.Collector.CollectError as e:
if 'Empty parameter set' in str(e):
# provide default data or skip
... Prevention
- Guard parametrize so it is only applied when data exists.
- Prefer 'skip' (default) over 'fail_at_collect' unless you want strict CI.
- Log when data sources are empty so you notice early.
When it happens
Trigger: A `@pytest.mark.parametrize('a', [])` decorator (or parametrize that evaluates to zero parameter rows) when pytest.ini / pyproject.toml sets `empty_parameter_set_mark = fail_at_collect`. Also triggered when a parametrize generator function yields nothing.
Common situations: Data-driven tests where the data source is empty at runtime (e.g. a filtered list, a weekend schedule, a disabled feature flag), combined with strict collection policy. CI configs that set fail_at_collect to surface empty suites.
Related errors
- Expected id to be a string or a `pytest.HIDDEN_PARAM`…
- pytest.param cannot add pytest.mark.usefixtures; see…
- absolute tolerance can't be NaN.
- absolute tolerance can't be negative
- absolute tolerance for a scalar value must be an int, float…
AI-assisted analysis of pytest-dev/pytest@0d6fbdeffa (2026-08-11).
Data as JSON: /api/errors/5de5e6b87c226eb8.
Report an issue: GitHub.
Appendix: source
Thrown at src/_pytest/mark/structures.py:76
def get_empty_parameterset_mark(
config: Config, argnames: Sequence[str], func
) -> MarkDecorator:
from ..nodes import Collector
argslisting = ", ".join(argnames)
_fs, lineno = getfslineno(func)
reason = f"got empty parameter set for ({argslisting})"
requested_mark: _EmptyParameterSetMark = config.getini(EMPTY_PARAMETERSET_OPTION)
match requested_mark:
case "skip":
return MARK_GEN.skip(reason=reason)
case "xfail":
return MARK_GEN.xfail(reason=reason, run=False)
case "fail_at_collect":
raise Collector.CollectError(
f"Empty parameter set in '{func.__name__}' at line {lineno + 1}"
)
case unreachable:
assert_never(unreachable)
class ParameterSet(NamedTuple):
"""A set of values for a set of parameters along with associated marks and
an optional ID for the set.
Examples::
pytest.param(1, 2, 3)
# ParameterSet(values=(1, 2, 3), marks=(), id=None)
pytest.param("hello", id="greeting")
# ParameterSet(values=("hello",), marks=(), id="greeting")
View on GitHub (pinned to 0d6fbdeffa)