Skip to content

Ignore some warnings and/or fix issue with @property #257

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

Open
samuelint opened this issue Mar 18, 2025 · 2 comments · Fixed by #258
Open

Ignore some warnings and/or fix issue with @property #257

samuelint opened this issue Mar 18, 2025 · 2 comments · Fixed by #258

Comments

@samuelint
Copy link

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

@mcous
Copy link
Owner

mcous commented Mar 18, 2025

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
Copy link
Owner

mcous commented Mar 19, 2025

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 mcous reopened this Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants