Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive PT011 when using pytest.raises as a function #17026

Open
hauh opened this issue Mar 27, 2025 · 1 comment
Open

False positive PT011 when using pytest.raises as a function #17026

hauh opened this issue Mar 27, 2025 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@hauh
Copy link

hauh commented Mar 27, 2025

Summary

pytest.raises can be used not only as a context manager but also as a function that takes a function to call for specified exception. In that case match parameter cannot be passed to the pytest.raises but can be checked on the returned exception info.

pytest.raises(Exception, func, *func_args, **func_kwargs).match("error message")

This line should not trigger PT011 error.

Version

0.11.2

@MichaReiser
Copy link
Member

This is about the legacy form of pytest.raises where a user passes a matching function (see legacy form).

I think we could simply ignore the legacy form for this check (test if there's a second positional argument and then skip the check)

@MichaReiser MichaReiser added bug Something isn't working good first issue Good for newcomers labels Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants