Closed rmoretto closed 4 years ago
This isn't a Hypothesis problem, it's because you're using a mutable default argument - attr.ib(..., default=[])
should instead be attr.ib(..., factory=list)
. See https://www.attrs.org/en/stable/examples.html#defaults and this blog post for a longer explanation.
So Hypothesis did find a bug, though maybe not how you expected it to!
Oh, I see! I'm feeling kinda stupid, should have paid more attention to the documentation, thank you for the response!
No worries, it happens to all of us. Feel proud that your bug report was so good that I could easily reproduce the problem - in fact good enough that I could diagnose the problem without reproducing it!
Hello!
So, I'm starting to test a project that uses a lot of
attrs
flavored classes, and when I started using hypothesis to generate some instances of those classes I noticed a strange behavior that I don't know if it is expected or not.Basically when I have a
attrs
class with some private attributes defined withattr.ib(init=False)
it seems that between tests the field is "saved" with its last value.I created two tests cases, one using normal classes and with attrs:
Without
attrs
test:With
attrs
test:In this test examples, it looks like that in the case of the class with
attr
the the_secondary_internal_storage
variable is being passed between runs, using the settingverbosity=Vervosity.debug
I get the following output:Hopefully this output helps to illustrate that the field
_secondary_internal_storage
is somehow "persisting" between runs.Reading the builder strategy doc I saw that hypothesis will try to infer required fields from attrs classes, maybe that is the underlying cause of this behavior?
I'm using: