Allow for easier import of `mocker.Mock | mocker.MagicMock` types
Kilo59 opened this issue · 0 comments
Kilo59 commented
I want to be able to import Mock
and MagicMock
types for type annotations.
I don't want to have to import from unittest.mock
because I am enforcing the use of pytest-mock
by banning the import of unittest.mock
.
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from pytest_mock import Mock, MagicMock, MockerFixture
@pytest.fixtue
def my_mock(mocker: MockerFixture) -> Mock:
return mocker.Mock()
@pytest.fixtue
def my_magic_mock(mocker: MockerFixture) -> MagicMock:
return mocker.MagicMock()
def test_something(my_mock: Mock):
...
I see 2 different approaches here.
- "Export"
unittest.mock
Mock
+MagicMock
in the top-level__init__
file - Add a
pytest_mock.types
subpackage. This could also include things likeANY
which would otherwise need to be imported fromunittest.mock
.
1
could be an issue because it might encourage users to use the Mock
/Mocker
as more than just type-annotations.