Add ASYNC430: lint rule for pytest.raises(ExceptionGroup)#431
Add ASYNC430: lint rule for pytest.raises(ExceptionGroup)#431Alm0stSurely wants to merge 1 commit intopython-trio:mainfrom
Conversation
Adds a new rule to detect usage of pytest.raises(ExceptionGroup) or pytest.raises(BaseExceptionGroup) in async functions, suggesting the use of pytest.RaisesGroup instead. This is recommended because RaisesGroup provides better support for exception group testing in async contexts, matching the structure of exception groups more accurately. Closes python-trio#430
There was a problem hiding this comment.
yeah, uh, this isn't great in a bunch of ways.
self.imports_exceptiongroup is unused and worthless.
Checking for import pytest is nonsensical, unless you were to use that to shortcut visit_Call - but that's a miniscule speedup at best. If anything you should check for from pytest import raises (and test).
pytest.ExceptionGroup is not a thing, check for the backport instead. And there should be tests for that.
This should work in sync functions.
There's absolutely no reason to do save_state.
The error message needs to be better, I don't think it's correct to say that pytest.raises(ExceptionGroup) is discouraged.
Don't use type: ignore in the test file unless it can be motivated with a comment.
and the tests are failing
This PR was clearly generated by an LLM, please be upfront with that.
|
You're right on all counts, and I sincerely apologize for wasting your time reviewing this. To be upfront: yes, I used an LLM to assist with this PR. That's not an excuse — it's my responsibility to verify and understand every line before submitting. I clearly didn't do that well enough here, and the result is a PR with unused code, nonsensical checks, and failing tests. That's on me. I'll take your feedback seriously:
I'm going to close this PR rather than pile more of your review time onto something that wasn't ready. If I come back to this issue, it'll be with something properly thought through and tested. Again, sorry for the noise. I appreciate you taking the time to explain what was wrong — I've learned from it. |
Problem
Using pytest.raises(ExceptionGroup) in async tests is often problematic because it doesn't properly handle the structure of exception groups. The pytest.RaisesGroup helper is designed specifically for this purpose.
Solution
Add a new lint rule ASYNC430 that detects usage of:
And suggests using pytest.RaisesGroup instead.
Implementation
Testing
Closes #430