Skip to content

Commit 5f28e21

Browse files
committed
test: Switch to unittest.mock from mock
Now that the minimum supported version of Python is 3.7, we can stop using the external mock requirement, and import it from unittest. I have also attempted to keep imports ordered. Fixes #377
1 parent 84bf637 commit 5f28e21

25 files changed

+32
-30
lines changed

noxfile.py

-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def default(session, install_grpc=True, prerelease=False, install_async_rest=Fal
124124

125125
session.install(
126126
"dataclasses",
127-
"mock",
128127
"pytest",
129128
"pytest-cov",
130129
"pytest-xdist",
@@ -280,7 +279,6 @@ def mypy(session):
280279
"types-setuptools",
281280
"types-requests",
282281
"types-protobuf",
283-
"types-mock",
284282
"types-dataclasses",
285283
)
286284
session.run("mypy", "google", "tests")

tests/asyncio/future/test_async_future.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
from unittest import mock
1617

17-
import mock
1818
import pytest
1919

2020
from google.api_core import exceptions

tests/asyncio/gapic/test_method_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
import datetime
16+
from unittest import mock
1617

17-
import mock
1818
import pytest
1919

2020
try:

tests/asyncio/operations_v1/test_operations_async_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
15+
from unittest import mock
16+
1617
import pytest
1718

1819
try:

tests/asyncio/retry/test_retry_streaming_async.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import asyncio
1516
import datetime
1617
import re
17-
import asyncio
18+
from unittest import mock
1819

19-
import mock
2020
import pytest
2121

2222
from google.api_core import exceptions

tests/asyncio/retry/test_retry_unary_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import datetime
1616
import re
17+
from unittest import mock
1718

18-
import mock
1919
import pytest
2020

2121
from google.api_core import exceptions

tests/asyncio/test_grpc_helpers_async.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
15+
from unittest import mock
16+
1617
import pytest # noqa: I202
1718

1819
try:

tests/asyncio/test_operation_async.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# limitations under the License.
1414

1515

16-
import mock
16+
from unittest import mock
17+
1718
import pytest
1819

1920
try:

tests/asyncio/test_page_iterator_async.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
import inspect
16+
from unittest import mock
1617

17-
import mock
1818
import pytest
1919

2020
from google.api_core import page_iterator_async

tests/asyncio/test_rest_streaming_async.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
# TODO: set random.seed explicitly in each test function.
1616
# See related issue: https://github.com/googleapis/python-api-core/issues/689.
1717

18-
import pytest # noqa: I202
19-
import mock
20-
2118
import datetime
2219
import logging
2320
import random
2421
import time
2522
from typing import List, AsyncIterator
23+
from unittest import mock
24+
25+
import pytest # noqa: I202
2626

2727
import proto
2828

tests/unit/future/test__helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
15+
from unittest import mock
1616

1717
from google.api_core.future import _helpers
1818

tests/unit/future/test_polling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import concurrent.futures
1616
import threading
1717
import time
18+
from unittest import mock
1819

19-
import mock
2020
import pytest
2121

2222
from google.api_core import exceptions, retry

tests/unit/gapic/test_method.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
import datetime
16+
from unittest import mock
1617

17-
import mock
1818
import pytest
1919

2020
try:

tests/unit/operations_v1/test_operations_rest_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# limitations under the License.
1515
#
1616
import os
17+
from unittest import mock
1718

18-
import mock
1919
import pytest
2020

2121
try:

tests/unit/retry/test_retry_base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import itertools
1616
import re
17+
from unittest import mock
1718

18-
import mock
1919
import pytest
2020
import requests.exceptions
2121

tests/unit/retry/test_retry_streaming.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
import re
16+
from unittest import mock
1617

17-
import mock
1818
import pytest
1919

2020
from google.api_core import exceptions

tests/unit/retry/test_retry_unary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import datetime
1616
import re
17+
from unittest import mock
1718

18-
import mock
1919
import pytest
2020

2121
from google.api_core import exceptions

tests/unit/test_bidi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import logging
1717
import queue
1818
import threading
19+
from unittest import mock
1920

20-
import mock
2121
import pytest
2222

2323
try:

tests/unit/test_exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import http.client
1616
import json
17+
from unittest import mock
1718

18-
import mock
1919
import pytest
2020
import requests
2121

tests/unit/test_extended_operation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import dataclasses
1616
import enum
1717
import typing
18+
from unittest import mock
1819

19-
import mock
2020
import pytest
2121

2222
from google.api_core import exceptions

tests/unit/test_grpc_helpers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
15+
from unittest import mock
16+
1617
import pytest
1718

1819
try:

tests/unit/test_operation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
# limitations under the License.
1414

1515

16-
import mock
16+
from unittest import mock
17+
1718
import pytest
1819

1920
try:

tests/unit/test_page_iterator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import math
1616
import types
17+
from unittest import mock
1718

18-
import mock
1919
import pytest
2020

2121
from google.api_core import page_iterator

tests/unit/test_path_template.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
from __future__ import unicode_literals
16+
from unittest import mock
1617

17-
import mock
1818
import pytest
1919

2020
from google.api import auth_pb2

tests/unit/test_timeout.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
import datetime
1616
import itertools
17-
18-
import mock
17+
from unittest import mock
1918

2019
from google.api_core import timeout as timeouts
2120

0 commit comments

Comments
 (0)