pytest-dev/pytest · error · CollectError

Empty parameter set in '{func.__name__}' at line {lineno + 1

Error message

Empty parameter set in '{func.__name__}' at line {lineno + 1}

What it means

Raised as a `Collector.CollectError` during collection when a `@pytest.mark.parametrize` produces an empty parameter set (e.g. empty list of values) and the `empty_parameter_set_mark` ini option is set to `fail_at_collect`. The other valid values are `skip` (default) and `xfail`, which instead attach a mark and continue. With `fail_at_collect`, collection aborts on that test.

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 98b357f69e)

Solutions

  1. Make the parametrize source non-empty, or guard the test so it is only collected when there is data.
  2. If an empty set is legitimately possible, set `empty_parameter_set_mark = skip` (default) or `xfail`.
  3. Generate the parameter list eagerly and assert it is non-empty before decorating, to fail with a clearer message.

Example fix

# before
@pytest.mark.parametrize('x', [])
def test_x(x): ...
# after
data = load_rows()
@pytest.mark.parametrize('x', data or [pytest.param(..., marks=pytest.mark.skip('no data'))])
def test_x(x): ...
Defensive patterns

Strategy: validation

Validate before calling

def ensure_non_empty(values):
    assert len(values) > 0, 'parametrize values are empty; fail_at_collect will abort'
    return values

Try / catch

try:
    pytest.main([test_file])
except Exception as e:
    if 'Empty parameter set' in str(e):
        ...

Prevention

When it happens

Trigger: @pytest.mark.parametrize('x', []) combined with `empty_parameter_set_mark = fail_at_collect` in pytest.ini / pyproject. Also when a generator/list comprehension yields no rows at runtime.

Common situations: Dynamically building parametrize values from an external source (CSV, DB query) that returns nothing; filtering out all rows; CI flag tightened to `fail_at_collect` to catch silent skips.

Related errors


AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04). Data as JSON: /data/errors/5de5e6b87c226eb8.json. Report an issue: GitHub.