Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Might mock.MagicMock be given a type parameter? #1605

Closed
nathanielmanistaatgoogle opened this issue Mar 25, 2024 · 1 comment
Closed

Might mock.MagicMock be given a type parameter? #1605

nathanielmanistaatgoogle opened this issue Mar 25, 2024 · 1 comment

Comments

@nathanielmanistaatgoogle
Copy link
Member

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.

@nathanielmanistaatgoogle
Copy link
Member Author

Ooops; wrong browser tab, wrong issue tracker. 😛 Please look over here instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant