-
-
Notifications
You must be signed in to change notification settings - Fork 547
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
Removing false flagging of assert statements from tests. #4236
Conversation
Signed-off-by: Pradyot Ranjan <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this ignore all asserts? We do not want asserts in the regular codebase.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #4236 +/- ##
========================================
Coverage 99.45% 99.45%
========================================
Files 288 288
Lines 22086 22089 +3
========================================
+ Hits 21966 21969 +3
Misses 120 120 ☔ View full report in Codecov by Sentry. |
Yes, it does and we discussed this – I don't think there is a way to configure it per path, and many other projects have the same issue: fossasia/query-server#332. We can look at |
Is codacy even doing anything for us? Can we just make ruff stricter? |
@valentinsulzer brought up the idea, and yes, we can do it because Ruff has the same rules available: https://docs.astral.sh/ruff/rules/#flake8-bandit-s |
I do think it is good to check for complexity (which codacy does), and asserts should be avoided in the main codebase. I think there is a lot we could improve by ramping up the ruff strictness. I think it should probably get a lot stricter based on the warnings I see in PyCharm |
Signed-off-by: Pradyot Ranjan <[email protected]>
@prady0t Looks like a good improvement to me. It caught asserts in main code as well. We probably want to raise exceptions or log warnings instead. |
I think from here we could try suppressing the asserts in codacy (if that does not cause issues in ruff's analysis) then just rely on ruff for most of it. Can you confirm that ruff triggers while the bandit yaml file suppresses codacy? |
Signed-off-by: Pradyot Ranjan <[email protected]>
…to codacy-asserts Merging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think from here we could try suppressing the asserts in codacy (if that does not cause issues in ruff's analysis) then just rely on ruff for most of it. Can you confirm that ruff triggers while the bandit yaml file suppresses codacy?
@kratman, I think it does, I see Codacy is happy now and doesn't flag the assert
statements in tests/
, while Ruff caught the ones to catch in pybamm/
. I shall approve this PR; IMO, we should add the rest of the flake8-bandit rules that Codacy uses to Ruff separately from here so that we can continue to use Codacy for now, and to let these changes be helpful for other PRs where tests are being modified.
I suspect codacy is "happy" because it only flags new findings. No new asserts were added in the tests here. I think Codacy is still going to have findings when you add new PyTest code. That is why I was asking @prady0t if the bandit yaml file could still be added while adding the ruff changes. |
In my local tests the bandit.yml file does not seem to stop ruff from finding asserts in the main code, so we should add that back |
But that's what we were wanting to do, right? i.e., have Ruff find asserts through its own rules in
I see. Yes, I've seen Codacy flagging just new findings too earlier. @prady0t, could you push a dummy commit here where you add an |
@agriyakhetarpal, @prady0t That is what I am pointing out. The bandit.yml file was remove from this PR. It should be put back otherwise codacy will continue to flag pytest updates |
Never mind – thanks to @kratman for pointing out. We need the bandit.yml
file that was added and then removed here to be added again.
Let me add it back. |
Signed-off-by: Pradyot Ranjan <[email protected]>
@prady0t Thanks, should be good now |
Coverage seems to drop because the in-line |
Let me add tests |
@prady0t While you are at it, can you add the type hints to the function call? |
Signed-off-by: Pradyot Ranjan <[email protected]>
…to codacy-asserts Merging.
Tests were passing before along with coverage, so I will merge this shortly |
Thanks @kratman |
@prady0t, I was able to find a better fix for this – could you open a PR? The fix is to add assert_used:
skips: ['*_test.py', '*test_*.py'] in |
…#4236) * Removing flase flagging of assert statements from tests Signed-off-by: Pradyot Ranjan <[email protected]> * style: pre-commit fixes * Using ruff to check for asserts Signed-off-by: Pradyot Ranjan <[email protected]> * Using TypeError instead of assert Signed-off-by: Pradyot Ranjan <[email protected]> * Adding back bandit file Signed-off-by: Pradyot Ranjan <[email protected]> * style: pre-commit fixes * Adding tests Signed-off-by: Pradyot Ranjan <[email protected]> --------- Signed-off-by: Pradyot Ranjan <[email protected]> Co-authored-by: Pradyot Ranjan <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Eric G. Kratz <[email protected]>
Codacy keeps flagging assert statements from tests. This added rule solves this.