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

Configure Codacy to stop flagging valid "assert" statements #332

Closed
2 tasks done
cclauss opened this issue Nov 12, 2017 · 10 comments
Closed
2 tasks done

Configure Codacy to stop flagging valid "assert" statements #332

cclauss opened this issue Nov 12, 2017 · 10 comments
Labels

Comments

@cclauss
Copy link
Contributor

cclauss commented Nov 12, 2017

I'm submitting a ...

  • bug report
  • feature request

Current behavior:
Put a valid assert statement in Python code and Codacy will flag it:

Expected behavior:

  • Codacy does not complain about valid Python.

Steps to fix:
https://support.codacy.com/hc/en-us/articles/207279979-Issues#2-remove-pattern

NOTES:

On Mon, Oct 30, 2017 at 12:52 PM, "Ruxandra Barbu" <ruxandra.barbu@codacy.intercom-mail.com>
wrote: 
Hi, thank you for contacting us.
Flagging the Python assert statements is a function of the Bandit linter itself.
You can ignore this issue in Codacy so it won´t affect the project. Please click here for
more details on how to ignore an issue/remove a pattern.
Please let me know if you have any other questions.

On Mon, Oct 30, 2017 at 01:55 AM, "cclauss" wrote: 
Why does Codacy flag the Python assert statements that pytest recommends? I know about the
optimization that eliminates the asserts commands from production code but 1) no one ever
does that and 2) if I did it, I would consider it a feature not a problem. Anyway, I how do
I configure Codacy to stop flagging the asserts that Pytest recommends?
@Dragneel7
Copy link
Contributor

@cclauss I am in interested in working on this issue.

@cclauss
Copy link
Contributor Author

cclauss commented Nov 25, 2017

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”::

Hi, thank you for contacting us.
Flagging the Python assert statements is a function of the Bandit linter itself.
You can ignore this issue in Codacy so it won´t affect the project.
Please click here for more details on how to ignore an issue/remove a pattern.
Please let me know if you have any other questions.

--
Ruxandra	Ruxandra from Codacy

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.

@Dragneel7
Copy link
Contributor

@cclauss will it be possible to work without "admin privileges"?

@cclauss
Copy link
Contributor Author

cclauss commented Nov 25, 2017

I tried unsuccessfully to do what that web page suggested.

@mariobehling Do you know who has Codacy admin privileges for this repo?

@cclauss
Copy link
Contributor Author

cclauss commented Dec 8, 2017

@vaibhavsingh97 Do you have admin rights to help solve issue?

Remorax pushed a commit to Remorax/query-server that referenced this issue Jan 14, 2018
* 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)
@cclauss
Copy link
Contributor Author

cclauss commented Jan 15, 2018

I found the solution!! Implemented in #385 Create a bandit.yml file at the root of the repo that contains:

skips: ['B101']

heilaaks added a commit to heilaaks/snippy that referenced this issue Jan 21, 2018
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>
@toonarmycaptain
Copy link

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.

@manoadamro
Copy link

manoadamro commented Jul 8, 2019

I actually stopped using codacy because of this, It was so frustrating that it couldn't figure out a file called tests/test_some_thing was a test file... I had 277 issues, all of them due to the use of assert.
surely any python file prefixed with test_ is a test file right? Especially if it's in a folder called tests

@toonarmycaptain
Copy link

toonarmycaptain commented Jul 8, 2019

@manoadamro Well unless you're working on assessments or worksheets maybe (eg test_templates, test_solutions), but once you run into this issue you'd think you'd change the filenames, or have all your tests under test_suite,
You can then do:

exclude_paths:
    - 'test_suite/**'

In your .codacy.yml file.

IsaccBarker added a commit to IsaccBarker/epiworldpy that referenced this issue Jun 28, 2024
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
@agriyakhetarpal
Copy link

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 bandit.yml, which should help flag statements selectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants