I commonly instantiate a Mock
object during unit tests. I am sick of:
- Having to type
from unittest.mock import Mock
- And then instantiate a
Mock
object viamock = Mock()
I am wondering, does pytest
, unittest.mock
, pytest-mock
, etc. have a built in way of passing in a Mock
object?
Here is what my current workflow looks like:
from unittest.mock import Mock
def test_something() -> None:
mock = Mock()
mock.func()
mock.func.assert_called_once()
Research
I know with pytest-mock
, I can at least get around the import via the mocker
fixture.
def test_something(mocker) -> None:
mock = mocker.Mock()
mock.func()
mock.func.assert_called_once()
I am hoping to just be able to do something like this:
def test_something(mock) -> None:
mock.func()
mock.func.assert_called_once()