pytest-dev/pytest · error · ValueError

You must specify at least one parameter to match on.

Error message

You must specify at least one parameter to match on.

What it means

Raised by RaisesExc when none of expected_exception, match, or check is provided. At least one of these is required to define what the matcher should look for.

Source

Thrown at src/_pytest/raises.py:622

        self,
        expected_exception: (
            type[BaseExcT_co_default] | tuple[type[BaseExcT_co_default], ...] | None
        ) = None,
        /,
        *,
        match: str | Pattern[str] | None = None,
        check: Callable[[BaseExcT_co_default], bool] | None = None,
    ):
        super().__init__(match=match, check=check)
        if isinstance(expected_exception, tuple):
            expected_exceptions = expected_exception
        elif expected_exception is None:
            expected_exceptions = ()
        else:
            expected_exceptions = (expected_exception,)

        if (expected_exceptions == ()) and match is None and check is None:
            raise ValueError("You must specify at least one parameter to match on.")

        self.expected_exceptions = tuple(
            self._parse_exc(e, expected="a BaseException type")
            for e in expected_exceptions
        )

        self._just_propagate = False

    def matches(
        self,
        exception: BaseException | None,
    ) -> TypeGuard[BaseExcT_co_default]:
        """Check if an exception matches the requirements of this :class:`RaisesExc`.
        If it fails, :attr:`RaisesExc.fail_reason` will be set.

        Examples::

            assert RaisesExc(ValueError).matches(my_exception):

View on GitHub (pinned to 98b357f69e)

Solutions

  1. Pass an exception type as the first argument.
  2. Or pass match='...' to match on the message only.
  3. Or pass check=lambda e: ... to define a custom matching predicate.

Example fix

// before
RaisesExc()
// after
RaisesExc(ValueError)
Defensive patterns

Strategy: validation

Validate before calling

if expected_exception is None and match is None and check is None:
    raise ValueError('provide at least one of: expected_exception, match, check')
RaisesExc(expected_exception, match=match, check=check)

Prevention

When it happens

Trigger: Constructing RaisesExc() with no arguments, or pytest.raises() in context-manager form with nothing. Hits raises.py:622.

Common situations: Programmatically building a RaisesExc and forgetting to set any constraint; a default-argument path that passes nothing; copy-paste of a partial template.

Related errors


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