[pytest-dev] pytest.raises message parameter

Bruno Oliveira nicoddemus at gmail.com
Thu Sep 13 21:52:53 EDT 2018


Hi everyone,

When using `pytest.raises`, it seems a lot of users confuse the parameter
`message` (a message to display if the with block finishes with no
exception) and `match` (a regular expression that the exception should
match), using the former when they meant the latter. This is very dangerous
as provides false positives.

https://docs.pytest.org/en/latest/reference.html#pytest-raises

Roman Yurchak posted a detailed example including PRs of projects that were
using the parameter incorrectly (using `message` when they meant `match`),
so this seems like a common problem.

So we have two proposals:

1, Deprecate `message` and use another parameter name. Little tricky to
find a suitable name that cannot be confused with `match`, but this is a
safe approach.

2. Removing the parameter altogether (after deprecating it). This would
make it match (heh) `pytest.warn`'s signature as well, which is a bonus.
This is an excellent option in the long term if there are no good use-cases
for it.

It would be helpful if people can provide good use cases to keep
`message`/`show_failure_message`, around, and also their opinion about this
matter.

I would like to keep the discussion in the issue itself, I'm using the
mailing list because few people here follow the GitHub issues by the sheer
amount of it:

https://github.com/pytest-dev/pytest/issues/3974

So let's please not continue this discussion here and use the issue itself.
Thanks!

Cheers,
Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20180913/3cdb8e04/attachment.html>


More information about the pytest-dev mailing list