Is it possible to disable an inspection for the whole file in PyCharm?
Yes.
NOTE: This answer is for this quoted question only (and not about “Maybe there’s another way to fix these problems? Maybe I’m using py.test incorrectly?”).
Settings/Preferences | Appearance & Behavior | Scopes
- Create a new scope that would include such “unwanted” file(s)
Settings/Preferences | Editor | Inspections
- Find that “problematic” inspection
- Select that newly created scope in the appropriate list (the old IDE versions had to use Right click and choose “Add scope”)
- Disable that inspection for that specific scope.
An example from my PhpStorm 2022.3 (would be the same or very similar in PyChram):
Alternatively (should work: although this depends on the actual inspection… I’m not PyCharm user so cannot check it out)
- Use Alt + Enter while caret is standing on the error/warning place in your code (or via light bulb icon using a mouse)
- Select correct entry from appeared popup menu
- Using Arrow Right key expand the submenu (with mouse it can be quite tricky to do: the hit box is rather small)
- Look for
Suppress inspection
option - It will add a special comment on the preceding line (or at the top of the file depending on what you choose) to ignore that inspection only
(this is how it looks in PhpStorm; available options can differ between inspections)