-
-
Notifications
You must be signed in to change notification settings - Fork 150
Closed
Description
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.mockMock+MagicMockin the top-level__init__file - Add a
pytest_mock.typessubpackage. This could also include things likeANYwhich 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.
imnotjames
Metadata
Metadata
Assignees
Labels
No labels