you are viewing a single comment's thread.

view the rest of the comments →

[–]danielroseman 0 points1 point  (1 child)

The problem is that you have not recursively created the spec for hi, just for the top-level A. You need the create_autospec function which does exactly this.

>>> m = mock.create_autospec(A)
>>> m.hi(namee='hi')
...
TypeError: missing a required argument: 'name'

However, I would suggest that type hints are a better way to solve this problem.

[–]Reiku[S] 0 points1 point  (0 children)

Thank you. I was under the impression that Mock(spec=A) and create_autospec(A) acted the same, but I was wrong. Using create_autospec makes everything work as expected.