theY4Kman / pycharm-pytest-imp

PyCharm pytest improvements plugin
https://plugins.jetbrains.com/plugin/14202-pytest-imp/
17 stars 2 forks source link

Suppress "method could be static" inspection on test methods #17

Open theY4Kman opened 1 year ago

theY4Kman commented 1 year ago

Currently, when defining test methods within a class, PyCharm will suggest Method 'test_xyz' may be static, with quick fixes to make a function out of the method, or to convert to a staticmethod.

image image

The issue with converting the method to a function is it removes the method from the class, completely changing the pytest semantics.

The issue with converting to a staticmethod is @staticmethod returns a descriptor, and not the test method itself; this means ordering of decorators is important — e.g. @pytest.mark.usefixtures('stuff') added above @staticmethod does nothing, but works if added below.

Since both of these quick fixes are erroneous or full of pitfalls, it seems wise to suppress the inspection entirely for pytest test methods.