Might mock.MagicMock be given a type parameter?
nathanielmanistaatgoogle opened this issue · comments
Nathaniel Manista commented
In the case of
class MyClass:
def method_that_exists_on_my_class(self):
pass
my_mock_thing = mock.create_autospec(MyClass)
my_mock_thing.method_that_exists_on_my_class()
my_mock_thing.method_that_does_not_exist_on_my_class()
my_mock_thing.method_that_exists_on_my_class.assert_called_once()
my_mock_thing.method_that_does_not_exist_on_my_class.assert_called_once()
it would be nice if the type of my_mock_thing
were mock.MagicMock[MyClass]
(instead of "raw" mock.MagicMock
) so that type-checkers could alert me that my call to my_mock_thing.method_that_does_not_exist_on_my_class
is a flaw in my test.
Nathaniel Manista commented
Ooops; wrong browser tab, wrong issue tracker. 😛 Please look over here instead.