diff --git a/pytest.ini b/pytest.ini index da506c41..afd6b82b 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,4 @@ [pytest] -; The standalone `mock` instead of stdlib `unittest.mock` is only for AsyncMock in Python 3.7. -mock_use_standalone_module = true asyncio_mode = auto addopts = --strict-markers diff --git a/requirements.txt b/requirements.txt index b97f81ba..1b8a2404 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,9 +12,6 @@ freezegun import-linter isort lxml -# Generally, `unittest.mock` is enough, but it lacks `AsyncMock` for Py 3.7. -# TODO: Once 3.7 is removed (Jun 2023), roll back to unittest.mock. -mock # Mypy requires typed-ast, which is broken on PyPy 3.7 (could work in PyPy 3.8). mypy==1.2.0; implementation_name == "cpython" pre-commit diff --git a/tests/admission/test_admission_server.py b/tests/admission/test_admission_server.py index bc490b80..636b9b1f 100644 --- a/tests/admission/test_admission_server.py +++ b/tests/admission/test_admission_server.py @@ -1,7 +1,7 @@ import contextlib +from unittest.mock import Mock import pytest -from mock import Mock import kopf from kopf._cogs.aiokits.aiovalues import Container diff --git a/tests/admission/test_serving_handler_selection.py b/tests/admission/test_serving_handler_selection.py index cdf287b1..b704a8ac 100644 --- a/tests/admission/test_serving_handler_selection.py +++ b/tests/admission/test_serving_handler_selection.py @@ -1,5 +1,6 @@ +from unittest.mock import Mock + import pytest -from mock import Mock import kopf from kopf._cogs.structs.ids import HandlerId diff --git a/tests/admission/test_serving_kwargs_passthrough.py b/tests/admission/test_serving_kwargs_passthrough.py index 25fdc39d..b93199ad 100644 --- a/tests/admission/test_serving_kwargs_passthrough.py +++ b/tests/admission/test_serving_kwargs_passthrough.py @@ -1,5 +1,6 @@ +from unittest.mock import Mock + import pytest -from mock import Mock import kopf from kopf._core.engines.admission import serve_admission_request diff --git a/tests/apis/test_iterjsonlines.py b/tests/apis/test_iterjsonlines.py index 91dc10ac..b120a844 100644 --- a/tests/apis/test_iterjsonlines.py +++ b/tests/apis/test_iterjsonlines.py @@ -1,4 +1,4 @@ -from mock import Mock +from unittest.mock import Mock from kopf._cogs.clients.api import iter_jsonlines diff --git a/tests/basic-structs/test_memories.py b/tests/basic-structs/test_memories.py index 65406804..9f0c3f45 100644 --- a/tests/basic-structs/test_memories.py +++ b/tests/basic-structs/test_memories.py @@ -1,4 +1,4 @@ -from mock import Mock +from unittest.mock import Mock from kopf._cogs.structs.bodies import Body from kopf._cogs.structs.ephemera import Memo diff --git a/tests/causation/test_kwargs.py b/tests/causation/test_kwargs.py index 6ee55c85..43fe6e6e 100644 --- a/tests/causation/test_kwargs.py +++ b/tests/causation/test_kwargs.py @@ -1,9 +1,9 @@ import dataclasses import logging from typing import Type +from unittest.mock import Mock import pytest -from mock import Mock from kopf._cogs.configs.configuration import OperatorSettings from kopf._cogs.structs import diffs diff --git a/tests/conftest.py b/tests/conftest.py index 683abc10..f7625ca3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,10 +8,10 @@ import sys import time from typing import Set +from unittest.mock import AsyncMock, Mock import aiohttp.web import pytest -from mock import AsyncMock, Mock import kopf from kopf._cogs.clients.auth import APIContext diff --git a/tests/handling/conftest.py b/tests/handling/conftest.py index 72d0fdc4..a9cec2b5 100644 --- a/tests/handling/conftest.py +++ b/tests/handling/conftest.py @@ -35,9 +35,9 @@ """ import dataclasses from typing import Callable +from unittest.mock import Mock import pytest -from mock import Mock import kopf from kopf._core.intents.causes import ChangingCause diff --git a/tests/handling/daemons/conftest.py b/tests/handling/daemons/conftest.py index 623d0d43..bdd0f846 100644 --- a/tests/handling/daemons/conftest.py +++ b/tests/handling/daemons/conftest.py @@ -1,10 +1,10 @@ import asyncio import contextlib import time +from unittest.mock import MagicMock, patch import freezegun import pytest -from mock import MagicMock, patch import kopf from kopf._cogs.aiokits.aiotoggles import ToggleSet diff --git a/tests/handling/subhandling/test_subhandling.py b/tests/handling/subhandling/test_subhandling.py index 9b2832d2..b83604fb 100644 --- a/tests/handling/subhandling/test_subhandling.py +++ b/tests/handling/subhandling/test_subhandling.py @@ -1,8 +1,8 @@ import asyncio import logging +from unittest.mock import Mock import pytest -from mock import Mock import kopf from kopf._cogs.structs.ephemera import Memo diff --git a/tests/handling/test_parametrization.py b/tests/handling/test_parametrization.py index df4209c2..4f73249a 100644 --- a/tests/handling/test_parametrization.py +++ b/tests/handling/test_parametrization.py @@ -1,6 +1,5 @@ import asyncio - -from mock import Mock +from unittest.mock import Mock import kopf from kopf._cogs.structs.ephemera import Memo diff --git a/tests/hierarchies/conftest.py b/tests/hierarchies/conftest.py index 11f2865d..8e340d34 100644 --- a/tests/hierarchies/conftest.py +++ b/tests/hierarchies/conftest.py @@ -1,5 +1,6 @@ +from unittest.mock import Mock + import pytest -from mock import Mock class CustomIterable: diff --git a/tests/hierarchies/test_owner_referencing.py b/tests/hierarchies/test_owner_referencing.py index e6b42b79..1e124960 100644 --- a/tests/hierarchies/test_owner_referencing.py +++ b/tests/hierarchies/test_owner_referencing.py @@ -1,7 +1,7 @@ import copy +from unittest.mock import call import pytest -from mock import call import kopf from kopf._cogs.structs.bodies import Body, RawBody, RawMeta diff --git a/tests/invocations/test_callbacks.py b/tests/invocations/test_callbacks.py index 175c5d6b..6f15e244 100644 --- a/tests/invocations/test_callbacks.py +++ b/tests/invocations/test_callbacks.py @@ -1,9 +1,9 @@ import functools import logging import traceback +from unittest.mock import Mock import pytest -from mock import Mock from kopf._cogs.structs.bodies import Body from kopf._cogs.structs.patches import Patch diff --git a/tests/persistence/test_states.py b/tests/persistence/test_states.py index c73a8195..32714230 100644 --- a/tests/persistence/test_states.py +++ b/tests/persistence/test_states.py @@ -1,8 +1,8 @@ import datetime +from unittest.mock import Mock import freezegun import pytest -from mock import Mock from kopf._cogs.configs.progress import SmartProgressStorage, StatusProgressStorage from kopf._cogs.structs.bodies import Body diff --git a/tests/reactor/conftest.py b/tests/reactor/conftest.py index 99adc261..af8e07db 100644 --- a/tests/reactor/conftest.py +++ b/tests/reactor/conftest.py @@ -1,8 +1,8 @@ import asyncio import functools +from unittest.mock import AsyncMock import pytest -from mock import AsyncMock from kopf._cogs.clients.watching import infinite_watch from kopf._core.reactor.queueing import watcher, worker as original_worker diff --git a/tests/registries/test_matching_of_callbacks.py b/tests/registries/test_matching_of_callbacks.py index 4aaff10c..e76cebd5 100644 --- a/tests/registries/test_matching_of_callbacks.py +++ b/tests/registries/test_matching_of_callbacks.py @@ -1,7 +1,7 @@ import dataclasses +from unittest.mock import Mock import pytest -from mock import Mock from kopf._cogs.structs.bodies import Body from kopf._cogs.structs.dicts import parse_field diff --git a/tests/registries/test_matching_of_resources.py b/tests/registries/test_matching_of_resources.py index db09c9a1..afa5d8ec 100644 --- a/tests/registries/test_matching_of_resources.py +++ b/tests/registries/test_matching_of_resources.py @@ -1,4 +1,4 @@ -from mock import Mock +from unittest.mock import Mock from kopf._cogs.structs.references import Resource, Selector from kopf._core.intents.registries import _matches_resource diff --git a/tests/settings/test_executor.py b/tests/settings/test_executor.py index 5494f617..f1dd522b 100644 --- a/tests/settings/test_executor.py +++ b/tests/settings/test_executor.py @@ -1,7 +1,6 @@ import concurrent.futures import threading - -from mock import MagicMock +from unittest.mock import MagicMock import kopf from kopf._core.actions.invocation import invoke diff --git a/tests/timing/test_throttling.py b/tests/timing/test_throttling.py index a77282a9..e6dc8537 100644 --- a/tests/timing/test_throttling.py +++ b/tests/timing/test_throttling.py @@ -1,8 +1,8 @@ import asyncio import logging +from unittest.mock import call import pytest -from mock import call from kopf._core.actions.throttlers import Throttler, throttled diff --git a/tests/utilities/aiotasks/test_coro_cancellation.py b/tests/utilities/aiotasks/test_coro_cancellation.py index f71ddc9b..97f8fef0 100644 --- a/tests/utilities/aiotasks/test_coro_cancellation.py +++ b/tests/utilities/aiotasks/test_coro_cancellation.py @@ -1,9 +1,9 @@ import asyncio import gc import warnings +from unittest.mock import AsyncMock, Mock import pytest -from mock import AsyncMock, Mock from kopf._cogs.aiokits.aiotasks import cancel_coro diff --git a/tests/utilities/aiotasks/test_scheduler.py b/tests/utilities/aiotasks/test_scheduler.py index 4a5a933c..2670748c 100644 --- a/tests/utilities/aiotasks/test_scheduler.py +++ b/tests/utilities/aiotasks/test_scheduler.py @@ -1,7 +1,7 @@ import asyncio +from unittest.mock import Mock import pytest -from mock import Mock from kopf._cogs.aiokits.aiotasks import Scheduler