-
Notifications
You must be signed in to change notification settings - Fork 264
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
Configure Codacy to stop flagging valid "assert" statements #332
Comments
@cclauss I am in interested in working on this issue. |
That is great news! It would help a lot if adding new pytests was viewed as a positive contribution by Codacy. This is what their support folks emailed to me about “removing the assert pattern”::
https://support.codacy.com/hc/en-us/articles/207279979-Issues#2-remove-pattern The process seems simple enough but it must be done by someone who has admin privileges of the project’s Codacy account. |
@cclauss will it be possible to work without "admin privileges"? |
I tried unsuccessfully to do what that web page suggested. @mariobehling Do you know who has Codacy admin privileges for this repo? |
@vaibhavsingh97 Do you have admin rights to help solve issue? |
* Fixes#283 UI changes (fossasia#309) * UI (fossasia#332) * Fixes#283 UI changes (fossasia#309) (fossasia#328) * Fixes#283 UI changes (fossasia#309) (fossasia#330) * Fixes#283 UI changes (fossasia#309) (fossasia#331)
I found the solution!! Implemented in #385 Create a bandit.yml file at the root of the repo that contains: skips: ['B101'] |
The Codacy seems to use Bandit which generates warning from every assert in Pytest tests /1/. This should be ignored with this file that skips B101: assert_used /2/. /1/ fossasia/query-server#332 /2/ https://docs.openstack.org/bandit/latest/plugins/assert_used.html Signed-off-by: Heikki Laaksonen <laaksonen.heikki.j@gmail.com>
It seems to me that the primary issue here is distinguishing between tests/testing code and project/production code. I don't want to turn off the checking for asserts in my project code, but I do want the asserts used (sensibly) in my tests to pass checks for asserts silently. Seems to me a solution would be to have a separate category for testing code, or code that pytest would run as tests, so I can turn on/off the "Assert used" pattern separately for testing/main project code. |
I actually stopped using codacy because of this, It was so frustrating that it couldn't figure out a file called |
@manoadamro Well unless you're working on assessments or worksheets maybe (eg
In your .codacy.yml file. |
This makes Bandit (and by extension Codacy) ignore the use of `assert`. Codacy can't seem to tell test from prod, so whenever `assert` is used in the test cases it will fail CI. This fix is not ideal (we'd still like to be warned about `assert` in real non-test code), but there appears to be no other way to fix it outside of mucking about in the admin portal (which would achieve no better effect). Reference: fossasia/query-server#332
This comes up very high in a Google search, so I'm posting this here just in case this helps others: One may add assert_used:
skips: ['*_test.py', '*test_*.py'] to their |
I'm submitting a ...
Current behavior:
Put a valid assert statement in Python code and Codacy will flag it:
Pytest recommends the use of asset statements. The fact that the code will be removed is actually a feature, not an issue. We want to encourage the addition of new pytests.
Expected behavior:
Steps to fix:
https://support.codacy.com/hc/en-us/articles/207279979-Issues#2-remove-pattern
NOTES:
The text was updated successfully, but these errors were encountered: