The new dataclasses.dataclass is very useful for describing the properties of a class, but it appears that Mocks of such decorated classes do not catch the members that are defined in the dataclass. I believe the root cause of this is the fact that unittest.mock.Mock generates the attributes of its spec object via `dir`, and the non-defaulted dataclass attributes do not appear in dir.
Given the utility in building classes with dataclass, it would be very useful if Mocks could see the class attributes of the dataclass.
Example code:
import dataclasses
import unittest.mock
@dataclasses.dataclass
class Foo:
name: str
baz: float
bar: int = 12
FooMock = unittest.mock.Mock(Foo)
fooMock = FooMock() # should fail: Foo.__init__ takes two arguments
# I would expect these to be True, but they are False
'name' in dir(fooMock)
'baz' in dir(fooMock)
'bar' in dir(fooMock) |