decoy icon indicating copy to clipboard operation
decoy copied to clipboard

Ignore some warnings and/or fix issue with @property

Open samuelint opened this issue 1 year ago • 2 comments

How to ignore some warnings? For example MissingSpecAttributeWarning

The problem, is that decoy see a missing spec when using @property on a class. But the stubbing / verify work perfectly.

Example:

class MyClass:
  @property
   def my_property(self) -> Some:
        return MyProperty()

Short term, how to ignore the warning so it does not pollute the pytest log? Long term: is it possible to fix the @property issue?

Thanks! BTW, this library is awesome. It clearly do not have enough stars

samuelint avatar Mar 18 '25 16:03 samuelint

Thanks for the report! There's definitely a bug with MissingSpecAttributeWarning, and you're not the first person to hit it. Thanks for narrowing the issue down to property access; I can now look into fixing this.

In the mean time, you can use Pytest's warning filtering system to ignore this warning in your tests. See Decoy's warnings docs for more details

pytestmark = pytest.mark.filterwarnings("ignore::decoy.warnings.MissingSpecAttributeWarning")

BTW, this library is awesome. It clearly do not have enough stars

😍 Feel free to spread the word!

mcous avatar Mar 18 '25 17:03 mcous

I released decoy 2.1.2, which makes the situation better, but MissingSpecAttributeWarning is still far too easy to trigger. I will follow up with a 2.1.3 in the coming days to scope the warning down to method calls only, since checking for property and attribute presence is, in hindsight, a terrible fit for how Python is actually written

mcous avatar Mar 19 '25 06:03 mcous