From 80130332a1872dfdb0bd5af81a1879ccd43bd1fc Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Mon, 30 Jun 2025 04:15:20 +0200 Subject: [PATCH] chore: remove use of old external "mock" module --- noxfile.py | 1 - setup.py | 1 - system_tests/system_tests_sync/test_external_accounts.py | 2 +- system_tests/system_tests_sync/test_mtls_http.py | 2 +- tests/compute_engine/test__metadata.py | 2 +- tests/compute_engine/test_credentials.py | 2 +- tests/conftest.py | 2 +- tests/crypt/test__python_rsa.py | 2 +- tests/oauth2/test__client.py | 2 +- tests/oauth2/test_challenges.py | 2 +- tests/oauth2/test_credentials.py | 2 +- tests/oauth2/test_gdch_credentials.py | 2 +- tests/oauth2/test_id_token.py | 2 +- tests/oauth2/test_reauth.py | 2 +- tests/oauth2/test_service_account.py | 2 +- tests/oauth2/test_sts.py | 2 +- tests/oauth2/test_webauthn_handler.py | 2 +- tests/oauth2/test_webauthn_handler_factory.py | 3 ++- tests/test__cloud_sdk.py | 2 +- tests/test__default.py | 2 +- tests/test__exponential_backoff.py | 3 ++- tests/test__oauth2client.py | 2 +- tests/test__refresh_worker.py | 2 +- tests/test_app_engine.py | 2 +- tests/test_aws.py | 2 +- tests/test_credentials.py | 2 +- tests/test_downscoped.py | 2 +- tests/test_external_account.py | 2 +- tests/test_external_account_authorized_user.py | 2 +- tests/test_iam.py | 2 +- tests/test_identity_pool.py | 2 +- tests/test_impersonated_credentials.py | 2 +- tests/test_jwt.py | 2 +- tests/test_metrics.py | 3 +-- tests/test_pluggable.py | 2 +- tests/transport/aio/test_aiohttp.py | 2 +- tests/transport/aio/test_sessions.py | 2 +- tests/transport/test__custom_tls_signer.py | 2 +- tests/transport/test__mtls_helper.py | 2 +- tests/transport/test_grpc.py | 2 +- tests/transport/test_mtls.py | 3 ++- tests/transport/test_requests.py | 2 +- tests/transport/test_urllib3.py | 2 +- tests_async/conftest.py | 2 +- tests_async/oauth2/test__client_async.py | 2 +- tests_async/oauth2/test_credentials_async.py | 2 +- tests_async/oauth2/test_id_token.py | 2 +- tests_async/oauth2/test_reauth_async.py | 2 +- tests_async/oauth2/test_service_account_async.py | 2 +- tests_async/test__default_async.py | 2 +- tests_async/test_jwt_async.py | 2 +- tests_async/transport/test_aiohttp_requests.py | 2 +- 52 files changed, 53 insertions(+), 53 deletions(-) diff --git a/noxfile.py b/noxfile.py index 1071be0ad..52674483d 100644 --- a/noxfile.py +++ b/noxfile.py @@ -79,7 +79,6 @@ def mypy(session): "types-pyOpenSSL", "types-requests", "types-setuptools", - "types-mock", ) session.run("mypy", "-p", "google", "-p", "tests", "-p", "tests_async") diff --git a/setup.py b/setup.py index 3874354fd..0dea4a04b 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,6 @@ "grpcio", "flask", "freezegun", - "mock", # TODO(https://github.com/googleapis/google-auth-library-python/issues/1736): Remove `oauth2client` from testing requirements once an extra is added for `oauth2client` dependency. "oauth2client", *pyjwt_extra_require, diff --git a/system_tests/system_tests_sync/test_external_accounts.py b/system_tests/system_tests_sync/test_external_accounts.py index 837d0064b..eb15a011d 100644 --- a/system_tests/system_tests_sync/test_external_accounts.py +++ b/system_tests/system_tests_sync/test_external_accounts.py @@ -48,7 +48,7 @@ from http.server import HTTPServer from google.oauth2 import service_account import pytest -from mock import patch +from unittest.mock import patch # Populate values from the output of scripts/setup_external_accounts.sh. _AUDIENCE_OIDC = "//iam.googleapis.com/projects/79992041559/locations/global/workloadIdentityPools/pool-73wslmxn/providers/oidc-73wslmxn" diff --git a/system_tests/system_tests_sync/test_mtls_http.py b/system_tests/system_tests_sync/test_mtls_http.py index bcf2a59da..0955a15bf 100644 --- a/system_tests/system_tests_sync/test_mtls_http.py +++ b/system_tests/system_tests_sync/test_mtls_http.py @@ -13,10 +13,10 @@ # limitations under the License. import json -import mock import os import time from os import path +from unittest import mock import google.auth diff --git a/tests/compute_engine/test__metadata.py b/tests/compute_engine/test__metadata.py index c90bc603a..f7c591aa4 100644 --- a/tests/compute_engine/test__metadata.py +++ b/tests/compute_engine/test__metadata.py @@ -17,8 +17,8 @@ import importlib import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/compute_engine/test_credentials.py b/tests/compute_engine/test_credentials.py index 03fe845b1..2118ee96d 100644 --- a/tests/compute_engine/test_credentials.py +++ b/tests/compute_engine/test_credentials.py @@ -13,8 +13,8 @@ # limitations under the License. import base64 import datetime +from unittest import mock -import mock import pytest # type: ignore import responses # type: ignore diff --git a/tests/conftest.py b/tests/conftest.py index 8080ec3fa..fbce2575e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,8 +14,8 @@ import os import sys +from unittest import mock -import mock import pytest # type: ignore diff --git a/tests/crypt/test__python_rsa.py b/tests/crypt/test__python_rsa.py index 4a4ebe44e..ec51e16bb 100644 --- a/tests/crypt/test__python_rsa.py +++ b/tests/crypt/test__python_rsa.py @@ -15,8 +15,8 @@ import io import json import os +from unittest import mock -import mock from pyasn1_modules import pem # type: ignore import pytest # type: ignore import rsa # type: ignore diff --git a/tests/oauth2/test__client.py b/tests/oauth2/test__client.py index 6a085729f..c7484b846 100644 --- a/tests/oauth2/test__client.py +++ b/tests/oauth2/test__client.py @@ -17,8 +17,8 @@ import json import os import urllib +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/oauth2/test_challenges.py b/tests/oauth2/test_challenges.py index 4116b913a..5a853ac78 100644 --- a/tests/oauth2/test_challenges.py +++ b/tests/oauth2/test_challenges.py @@ -17,8 +17,8 @@ import base64 import os import sys +from unitest import mock -import mock import pytest # type: ignore import pyu2f # type: ignore diff --git a/tests/oauth2/test_credentials.py b/tests/oauth2/test_credentials.py index 7d2a9b872..a30dbccee 100644 --- a/tests/oauth2/test_credentials.py +++ b/tests/oauth2/test_credentials.py @@ -17,8 +17,8 @@ import os import pickle import sys +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/oauth2/test_gdch_credentials.py b/tests/oauth2/test_gdch_credentials.py index 63075aba0..b889744e6 100644 --- a/tests/oauth2/test_gdch_credentials.py +++ b/tests/oauth2/test_gdch_credentials.py @@ -16,8 +16,8 @@ import datetime import json import os +from unittest import mock -import mock import pytest # type: ignore import requests diff --git a/tests/oauth2/test_id_token.py b/tests/oauth2/test_id_token.py index ff3d4b6d8..68b74f11b 100644 --- a/tests/oauth2/test_id_token.py +++ b/tests/oauth2/test_id_token.py @@ -14,8 +14,8 @@ import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import environment_vars diff --git a/tests/oauth2/test_reauth.py b/tests/oauth2/test_reauth.py index a95367a2b..ef19e4c84 100644 --- a/tests/oauth2/test_reauth.py +++ b/tests/oauth2/test_reauth.py @@ -13,8 +13,8 @@ # limitations under the License. import copy +from unittest import mock -import mock import pytest # type: ignore from google.auth import exceptions diff --git a/tests/oauth2/test_service_account.py b/tests/oauth2/test_service_account.py index 91a7d93e0..2aeab2ac5 100644 --- a/tests/oauth2/test_service_account.py +++ b/tests/oauth2/test_service_account.py @@ -15,8 +15,8 @@ import datetime import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/oauth2/test_sts.py b/tests/oauth2/test_sts.py index e0fb4ae23..61cf3bf32 100644 --- a/tests/oauth2/test_sts.py +++ b/tests/oauth2/test_sts.py @@ -15,8 +15,8 @@ import http.client as http_client import json import urllib +from unittest import mock -import mock import pytest # type: ignore from google.auth import exceptions diff --git a/tests/oauth2/test_webauthn_handler.py b/tests/oauth2/test_webauthn_handler.py index 9fba266da..1dd75d6e1 100644 --- a/tests/oauth2/test_webauthn_handler.py +++ b/tests/oauth2/test_webauthn_handler.py @@ -1,7 +1,7 @@ import json import struct +from unittest import mock -import mock import pytest # type: ignore from google.auth import exceptions diff --git a/tests/oauth2/test_webauthn_handler_factory.py b/tests/oauth2/test_webauthn_handler_factory.py index 47890ce4b..1323de909 100644 --- a/tests/oauth2/test_webauthn_handler_factory.py +++ b/tests/oauth2/test_webauthn_handler_factory.py @@ -1,4 +1,5 @@ -import mock +from unittest import mock + import pytest # type: ignore from google.oauth2 import webauthn_handler diff --git a/tests/test__cloud_sdk.py b/tests/test__cloud_sdk.py index e45c65bd9..dd14bcebe 100644 --- a/tests/test__cloud_sdk.py +++ b/tests/test__cloud_sdk.py @@ -17,8 +17,8 @@ import os import subprocess import sys +from unittest import mock -import mock import pytest # type: ignore from google.auth import _cloud_sdk diff --git a/tests/test__default.py b/tests/test__default.py index e42b4dd94..4b294de2b 100644 --- a/tests/test__default.py +++ b/tests/test__default.py @@ -14,8 +14,8 @@ import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import _default diff --git a/tests/test__exponential_backoff.py b/tests/test__exponential_backoff.py index b7b6877b2..7ac05ba73 100644 --- a/tests/test__exponential_backoff.py +++ b/tests/test__exponential_backoff.py @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + import pytest # type: ignore from google.auth import _exponential_backoff diff --git a/tests/test__oauth2client.py b/tests/test__oauth2client.py index 2d4a809bb..730f07450 100644 --- a/tests/test__oauth2client.py +++ b/tests/test__oauth2client.py @@ -16,8 +16,8 @@ import importlib import os import sys +from unittest import mock -import mock import pytest # type: ignore try: diff --git a/tests/test__refresh_worker.py b/tests/test__refresh_worker.py index c25965d10..f4e797c75 100644 --- a/tests/test__refresh_worker.py +++ b/tests/test__refresh_worker.py @@ -16,8 +16,8 @@ import random import threading import time +from unittest import mock -import mock import pytest # type: ignore from google.auth import _refresh_worker, credentials, exceptions diff --git a/tests/test_app_engine.py b/tests/test_app_engine.py index ca085bd69..10b7bf371 100644 --- a/tests/test_app_engine.py +++ b/tests/test_app_engine.py @@ -13,8 +13,8 @@ # limitations under the License. import datetime +from unittest import mock -import mock import pytest # type: ignore from google.auth import app_engine diff --git a/tests/test_aws.py b/tests/test_aws.py index df1f02e7d..44de5d594 100644 --- a/tests/test_aws.py +++ b/tests/test_aws.py @@ -17,8 +17,8 @@ import json import os import urllib.parse +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers, external_account diff --git a/tests/test_credentials.py b/tests/test_credentials.py index e11bcb4e5..9d56e85d9 100644 --- a/tests/test_credentials.py +++ b/tests/test_credentials.py @@ -13,8 +13,8 @@ # limitations under the License. import datetime +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/test_downscoped.py b/tests/test_downscoped.py index fe6e291c7..3c78f67bb 100644 --- a/tests/test_downscoped.py +++ b/tests/test_downscoped.py @@ -16,8 +16,8 @@ import http.client as http_client import json import urllib +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/test_external_account.py b/tests/test_external_account.py index bddcb4afa..eb0764e1b 100644 --- a/tests/test_external_account.py +++ b/tests/test_external_account.py @@ -16,8 +16,8 @@ import http.client as http_client import json import urllib +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/test_external_account_authorized_user.py b/tests/test_external_account_authorized_user.py index 93926a131..3ff8c0bff 100644 --- a/tests/test_external_account_authorized_user.py +++ b/tests/test_external_account_authorized_user.py @@ -15,8 +15,8 @@ import datetime import http.client as http_client import json +from unittest import mock -import mock import pytest # type: ignore from google.auth import exceptions diff --git a/tests/test_iam.py b/tests/test_iam.py index 01c2fa085..26a4c825a 100644 --- a/tests/test_iam.py +++ b/tests/test_iam.py @@ -16,8 +16,8 @@ import datetime import http.client as http_client import json +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/test_identity_pool.py b/tests/test_identity_pool.py index 41fd18892..7f897f932 100644 --- a/tests/test_identity_pool.py +++ b/tests/test_identity_pool.py @@ -18,8 +18,8 @@ import json import os import urllib +from unittest import mock -import mock from OpenSSL import crypto import pytest # type: ignore diff --git a/tests/test_impersonated_credentials.py b/tests/test_impersonated_credentials.py index 4aa357e3e..35eaa1021 100644 --- a/tests/test_impersonated_credentials.py +++ b/tests/test_impersonated_credentials.py @@ -17,8 +17,8 @@ import http.client as http_client import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/test_jwt.py b/tests/test_jwt.py index 28660ea33..3029d6f1d 100644 --- a/tests/test_jwt.py +++ b/tests/test_jwt.py @@ -16,8 +16,8 @@ import datetime import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/test_metrics.py b/tests/test_metrics.py index ba9389267..c2e4014a0 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -13,8 +13,7 @@ # limitations under the License. import platform - -import mock +from unittest import mock from google.auth import metrics from google.auth import version diff --git a/tests/test_pluggable.py b/tests/test_pluggable.py index 6bee054c5..3fb76e897 100644 --- a/tests/test_pluggable.py +++ b/tests/test_pluggable.py @@ -15,8 +15,8 @@ import json import os import subprocess +from unittest import mock -import mock import pytest # type: ignore from google.auth import exceptions diff --git a/tests/transport/aio/test_aiohttp.py b/tests/transport/aio/test_aiohttp.py index 632abff25..13f86ba34 100644 --- a/tests/transport/aio/test_aiohttp.py +++ b/tests/transport/aio/test_aiohttp.py @@ -13,9 +13,9 @@ # limitations under the License. import asyncio +from unittest.mock import AsyncMock, Mock, patch from aioresponses import aioresponses # type: ignore -from mock import AsyncMock, Mock, patch import pytest # type: ignore import pytest_asyncio # type: ignore diff --git a/tests/transport/aio/test_sessions.py b/tests/transport/aio/test_sessions.py index c91a7c40a..697c17a58 100644 --- a/tests/transport/aio/test_sessions.py +++ b/tests/transport/aio/test_sessions.py @@ -14,9 +14,9 @@ import asyncio from typing import AsyncGenerator +from unittest.mock import Mock, patch from aioresponses import aioresponses # type: ignore -from mock import Mock, patch import pytest # type: ignore from google.auth.aio.credentials import AnonymousCredentials diff --git a/tests/transport/test__custom_tls_signer.py b/tests/transport/test__custom_tls_signer.py index 3a33c2c02..273a45869 100644 --- a/tests/transport/test__custom_tls_signer.py +++ b/tests/transport/test__custom_tls_signer.py @@ -14,8 +14,8 @@ import base64 import ctypes import os +from unittest import mock -import mock import pytest # type: ignore from requests.packages.urllib3.util.ssl_ import create_urllib3_context # type: ignore import urllib3.contrib.pyopenssl # type: ignore diff --git a/tests/transport/test__mtls_helper.py b/tests/transport/test__mtls_helper.py index f6e20b726..d16959042 100644 --- a/tests/transport/test__mtls_helper.py +++ b/tests/transport/test__mtls_helper.py @@ -14,8 +14,8 @@ import os import re +from unittes import mock -import mock from OpenSSL import crypto import pytest # type: ignore diff --git a/tests/transport/test_grpc.py b/tests/transport/test_grpc.py index ed3f3ee83..7ebd14758 100644 --- a/tests/transport/test_grpc.py +++ b/tests/transport/test_grpc.py @@ -15,8 +15,8 @@ import datetime import os import time +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests/transport/test_mtls.py b/tests/transport/test_mtls.py index ea549ae14..0b02c68a7 100644 --- a/tests/transport/test_mtls.py +++ b/tests/transport/test_mtls.py @@ -12,7 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock + import pytest # type: ignore from google.auth import exceptions diff --git a/tests/transport/test_requests.py b/tests/transport/test_requests.py index 0da3e36d9..932a7c0b3 100644 --- a/tests/transport/test_requests.py +++ b/tests/transport/test_requests.py @@ -17,9 +17,9 @@ import http.client as http_client import os import sys +from unittest import mock import freezegun -import mock import OpenSSL import pytest # type: ignore import requests diff --git a/tests/transport/test_urllib3.py b/tests/transport/test_urllib3.py index e83230032..50044df15 100644 --- a/tests/transport/test_urllib3.py +++ b/tests/transport/test_urllib3.py @@ -15,8 +15,8 @@ import http.client as http_client import os import sys +from unittest import mock -import mock import OpenSSL import pytest # type: ignore import urllib3 # type: ignore diff --git a/tests_async/conftest.py b/tests_async/conftest.py index f13dec0e4..55fd26463 100644 --- a/tests_async/conftest.py +++ b/tests_async/conftest.py @@ -14,8 +14,8 @@ import os import sys +from unittest import mock -import mock import pytest # type: ignore diff --git a/tests_async/oauth2/test__client_async.py b/tests_async/oauth2/test__client_async.py index 7ffbc7ae1..e818e1127 100644 --- a/tests_async/oauth2/test__client_async.py +++ b/tests_async/oauth2/test__client_async.py @@ -16,8 +16,8 @@ import http.client as http_client import json import urllib +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests_async/oauth2/test_credentials_async.py b/tests_async/oauth2/test_credentials_async.py index fba0c3cf9..03f882d5c 100644 --- a/tests_async/oauth2/test_credentials_async.py +++ b/tests_async/oauth2/test_credentials_async.py @@ -17,8 +17,8 @@ import os import pickle import sys +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests_async/oauth2/test_id_token.py b/tests_async/oauth2/test_id_token.py index 9be086dca..51d85daf2 100644 --- a/tests_async/oauth2/test_id_token.py +++ b/tests_async/oauth2/test_id_token.py @@ -14,8 +14,8 @@ import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import environment_vars diff --git a/tests_async/oauth2/test_reauth_async.py b/tests_async/oauth2/test_reauth_async.py index 40ca92717..4874a3728 100644 --- a/tests_async/oauth2/test_reauth_async.py +++ b/tests_async/oauth2/test_reauth_async.py @@ -13,8 +13,8 @@ # limitations under the License. import copy +from unittest import mock -import mock import pytest # type: ignore from google.auth import exceptions diff --git a/tests_async/oauth2/test_service_account_async.py b/tests_async/oauth2/test_service_account_async.py index 176992f77..5a9a89fca 100644 --- a/tests_async/oauth2/test_service_account_async.py +++ b/tests_async/oauth2/test_service_account_async.py @@ -13,8 +13,8 @@ # limitations under the License. import datetime +from unittest import mock -import mock import pytest # type: ignore from google.auth import _helpers diff --git a/tests_async/test__default_async.py b/tests_async/test__default_async.py index e1dbb1c09..a1268bdc0 100644 --- a/tests_async/test__default_async.py +++ b/tests_async/test__default_async.py @@ -14,8 +14,8 @@ import json import os +from unittest import mock -import mock import pytest # type: ignore from google.auth import _credentials_async as credentials diff --git a/tests_async/test_jwt_async.py b/tests_async/test_jwt_async.py index f24a0a99d..9d9eca4e2 100644 --- a/tests_async/test_jwt_async.py +++ b/tests_async/test_jwt_async.py @@ -14,8 +14,8 @@ import datetime import json +from unittest import mock -import mock import pytest # type: ignore from google.auth import _jwt_async as jwt_async diff --git a/tests_async/transport/test_aiohttp_requests.py b/tests_async/transport/test_aiohttp_requests.py index d00955a7d..a67cd52b6 100644 --- a/tests_async/transport/test_aiohttp_requests.py +++ b/tests_async/transport/test_aiohttp_requests.py @@ -14,7 +14,7 @@ import aiohttp # type: ignore from aioresponses import aioresponses, core # type: ignore -import mock +from unittest import mock import pytest # type: ignore from tests_async.transport import async_compliance