attrs
attrs copied to clipboard
unittest mock missed attrs class when slots=False
Sorry for opening the same thread in two different repositories, I did my research but couldn't find a working solution. I think this should be a common use case and I don't believe I am the first one to hit this issue.
When slots=False, Mock doesn't work. I

from unittest.mock import create_autospec
from attrs import frozen, field, fields, define
@define(slots=True)
class SlottedClass:
a: int
b: int
tmp = SlottedClass(1,1)
@define(slots=False)
class NonSlottedClass:
a: int
b: int
tmp = SlottedClass(1,1)
slotted = create_autospec(slotted)
non_slotted = create_autospec(NonSlottedClass)
slotted.a, slotted.b
non_slotted.a, non_slotted.b
Original Thread: https://github.com/python/cpython/issues/93133
As you've found out in the CPython bug, it's not an attrs issue but apparently a slots issue…let's hope they fix it in a general way and not special-case DCs. :-/
Looks like Python core doesn't care and I don't think we can do anything about this, since mock probably inspects __slots__ and __dict__?