PyCharm noinspection for whole file?

gak picture gak · Apr 9, 2014 · Viewed 8k times · Source

Is it possible to disable an inspection for the whole file in PyCharm?

The reason this is needed is when dealing with py.test. It uses fixtures which appear to shadow function parameters, and at the same time cause unresolved references. e.g.:

from myfixtures import user  # Unused import statement warning

def test_is_awesome(user):  # Shadows name 'user' from outer scope warning
    assert user.is_awesome()

There is also other warnings from py.test, such as using pytest.raises() causes a "Can not find reference 'raises'" in pytest.py.

Maybe there's another way to fix these problems? Maybe I'm using py.test incorrectly?

Answer

LazyOne picture LazyOne · Apr 9, 2014

Is it possible to disable an inspection for the whole file in PyCharm?

Yes. This answer is for this question only (and not about "Maybe there's another way to fix these problems? Maybe I'm using py.test incorrectly?").

  1. "Settings | Scopes"
  2. Create new scope that would include such "unwanted" file(s)
  3. "Settings | Inspections"
  4. Find "problematic" inspection
  5. Right click and choose "Add scope"
  6. Disable that inspection for that specific scope

Alternatively (may work or may not: depends on actual inspection .. and I'm not sure if it actually works in PyCharm this way -- not a PyCharm user myself unfortunately)

  1. Alt + Enter while caret is standing on error/warning place in your code
  2. Select correct entry from appeared popup menu
  3. Using Arrow Right key expand submenu
  4. Look for "Suppress inspection" option

This is how it looks in PhpStorm (screenshot shows "suppress for statement" option and not "suppress for whole file"):

enter image description here

Related: https://stackoverflow.com/a/20803118/783119