Skip to content

Commit 34ca759

Browse files
authored
PYTHON-5113 - Refactor test utils for async (#2149)
1 parent 4322fdf commit 34ca759

File tree

101 files changed

+1184
-1130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1184
-1130
lines changed

Diff for: test/asynchronous/test_async_cancellation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import asyncio
1919
import sys
20-
from test.utils import async_get_pool, delay, one
20+
from test.asynchronous.utils import async_get_pool
21+
from test.utils_shared import delay, one
2122

2223
sys.path[0:0] = [""]
2324

Diff for: test/asynchronous/test_auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
async_client_context,
3131
unittest,
3232
)
33-
from test.utils import AllowListEventListener, delay, ignore_deprecations
33+
from test.utils_shared import AllowListEventListener, delay, ignore_deprecations
3434

3535
import pytest
3636

Diff for: test/asynchronous/test_bulk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
sys.path[0:0] = [""]
2525

2626
from test.asynchronous import AsyncIntegrationTest, async_client_context, remove_all_users, unittest
27-
from test.utils import async_wait_until
27+
from test.utils_shared import async_wait_until
2828

2929
from bson.binary import Binary, UuidRepresentation
3030
from bson.codec_options import CodecOptions

Diff for: test/asynchronous/test_change_stream.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
unittest,
3737
)
3838
from test.asynchronous.unified_format import generate_test_classes
39-
from test.utils import (
39+
from test.utils_shared import (
4040
AllowListEventListener,
4141
EventListener,
4242
OvertCommandListener,

Diff for: test/asynchronous/test_client.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@
6060
unittest,
6161
)
6262
from test.asynchronous.pymongo_mocks import AsyncMockClient
63+
from test.asynchronous.utils import (
64+
async_get_pool,
65+
async_wait_until,
66+
asyncAssertRaisesExactly,
67+
)
6368
from test.test_binary import BinaryData
64-
from test.utils import (
69+
from test.utils_shared import (
6570
NTHREADS,
6671
CMAPListener,
6772
FunctionCallRecorder,
68-
async_get_pool,
69-
async_wait_until,
70-
asyncAssertRaisesExactly,
7173
delay,
7274
gevent_monkey_patched,
7375
is_greenthread_patched,

Diff for: test/asynchronous/test_client_bulk_write.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
async_client_context,
2626
unittest,
2727
)
28-
from test.utils import (
28+
from test.utils_shared import (
2929
OvertCommandListener,
3030
)
3131
from unittest.mock import patch

Diff for: test/asynchronous/test_collation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import functools
1919
import warnings
2020
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
21-
from test.utils import EventListener, OvertCommandListener
21+
from test.utils_shared import EventListener, OvertCommandListener
2222
from typing import Any
2323

2424
from pymongo.asynchronous.helpers import anext

Diff for: test/asynchronous/test_collection.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys
2222
from codecs import utf_8_decode
2323
from collections import defaultdict
24+
from test.asynchronous.utils import async_get_pool, async_is_mongos
2425
from typing import Any, Iterable, no_type_check
2526

2627
from pymongo.asynchronous.database import AsyncDatabase
@@ -33,12 +34,10 @@
3334
AsyncUnitTest,
3435
async_client_context,
3536
)
36-
from test.utils import (
37+
from test.utils_shared import (
3738
IMPOSSIBLE_WRITE_CONCERN,
3839
EventListener,
3940
OvertCommandListener,
40-
async_get_pool,
41-
async_is_mongos,
4241
async_wait_until,
4342
)
4443

Diff for: test/asynchronous/test_comment.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
sys.path[0:0] = [""]
2323
from asyncio import iscoroutinefunction
2424
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
25-
from test.utils import OvertCommandListener
25+
from test.utils_shared import OvertCommandListener
2626

2727
from bson.dbref import DBRef
2828
from pymongo.asynchronous.command_cursor import AsyncCommandCursor

Diff for: test/asynchronous/test_concurrency.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import asyncio
1919
import time
2020
from test.asynchronous import AsyncIntegrationTest, async_client_context
21-
from test.utils import delay
21+
from test.utils_shared import delay
2222

2323
_IS_SYNC = False
2424

Diff for: test/asynchronous/test_connection_monitoring.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
import sys
2121
import time
2222
from pathlib import Path
23+
from test.asynchronous.utils import async_get_pool, async_get_pools
2324

2425
sys.path[0:0] = [""]
2526

26-
from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
27+
from test.asynchronous import AsyncIntegrationTest, async_client_context, client_knobs, unittest
2728
from test.asynchronous.pymongo_mocks import DummyMonitor
2829
from test.asynchronous.utils_spec_runner import AsyncSpecTestCreator, SpecRunnerTask
29-
from test.utils import (
30+
from test.utils_shared import (
3031
CMAPListener,
31-
async_client_context,
32-
async_get_pool,
33-
async_get_pools,
3432
async_wait_until,
3533
camel_to_snake,
3634
)

Diff for: test/asynchronous/test_connections_survive_primary_stepdown_spec.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from __future__ import annotations
1717

1818
import sys
19+
from test.asynchronous.utils import async_ensure_all_connected
1920

2021
sys.path[0:0] = [""]
2122

@@ -25,9 +26,8 @@
2526
unittest,
2627
)
2728
from test.asynchronous.helpers import async_repl_set_step_down
28-
from test.utils import (
29+
from test.utils_shared import (
2930
CMAPListener,
30-
async_ensure_all_connected,
3131
)
3232

3333
from bson import SON

Diff for: test/asynchronous/test_cursor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
sys.path[0:0] = [""]
3232

3333
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
34-
from test.utils import (
34+
from test.utils_shared import (
3535
AllowListEventListener,
3636
EventListener,
3737
OvertCommandListener,

Diff for: test/asynchronous/test_data_lake.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from test.asynchronous import AsyncIntegrationTest, AsyncUnitTest, async_client_context, unittest
2727
from test.asynchronous.unified_format import generate_test_classes
28-
from test.utils import (
28+
from test.utils_shared import (
2929
OvertCommandListener,
3030
)
3131

Diff for: test/asynchronous/test_database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from test import unittest
2727
from test.asynchronous import AsyncIntegrationTest, async_client_context
2828
from test.test_custom_types import DECIMAL_CODECOPTS
29-
from test.utils import (
29+
from test.utils_shared import (
3030
IMPOSSIBLE_WRITE_CONCERN,
3131
OvertCommandListener,
3232
async_wait_until,

Diff for: test/asynchronous/test_discovery_and_monitoring.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,32 @@
2626

2727
sys.path[0:0] = [""]
2828

29-
from test.asynchronous import AsyncIntegrationTest, AsyncPyMongoTestCase, AsyncUnitTest, unittest
29+
from test.asynchronous import (
30+
AsyncIntegrationTest,
31+
AsyncPyMongoTestCase,
32+
AsyncUnitTest,
33+
async_client_context,
34+
unittest,
35+
)
3036
from test.asynchronous.pymongo_mocks import DummyMonitor
3137
from test.asynchronous.unified_format import generate_test_classes
32-
from test.utils import (
38+
from test.asynchronous.utils import (
39+
async_get_pool,
40+
)
41+
from test.utils_shared import (
3342
CMAPListener,
3443
HeartbeatEventListener,
3544
HeartbeatEventsListListener,
3645
assertion_context,
3746
async_barrier_wait,
38-
async_client_context,
3947
async_create_barrier,
40-
async_get_pool,
4148
async_wait_until,
4249
server_name_to_type,
4350
)
4451
from unittest.mock import patch
4552

4653
from bson import Timestamp, json_util
47-
from pymongo import AsyncMongoClient, common, monitoring
54+
from pymongo import common, monitoring
4855
from pymongo.asynchronous.settings import TopologySettings
4956
from pymongo.asynchronous.topology import Topology, _ErrorContext
5057
from pymongo.errors import (
@@ -291,7 +298,7 @@ async def test_ignore_stale_connection_errors(self):
291298
if not _IS_SYNC and sys.version_info < (3, 11):
292299
self.skipTest("Test requires asyncio.Barrier (added in Python 3.11)")
293300
N_TASKS = 5
294-
barrier = async_create_barrier(N_TASKS, timeout=30)
301+
barrier = async_create_barrier(N_TASKS)
295302
client = await self.async_rs_or_single_client(minPoolSize=N_TASKS)
296303

297304
# Wait for initial discovery.

Diff for: test/asynchronous/test_dns.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
async_client_context,
3030
unittest,
3131
)
32-
from test.utils import async_wait_until
32+
from test.utils_shared import async_wait_until
3333

3434
from pymongo.common import validate_read_preference_tags
3535
from pymongo.errors import ConfigurationError

Diff for: test/asynchronous/test_encryption.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
KMIP_CREDS,
6565
LOCAL_MASTER_KEY,
6666
)
67-
from test.utils import (
67+
from test.utils_shared import (
6868
AllowListEventListener,
6969
OvertCommandListener,
7070
TopologyEventListener,

Diff for: test/asynchronous/test_examples.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
sys.path[0:0] = [""]
2727

2828
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
29-
from test.utils import async_wait_until
29+
from test.utils_shared import async_wait_until
3030

3131
import pymongo
3232
from pymongo.asynchronous.helpers import anext

Diff for: test/asynchronous/test_grid_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
sys.path[0:0] = [""]
3535

36-
from test.utils import OvertCommandListener
36+
from test.utils_shared import OvertCommandListener
3737

3838
from bson.objectid import ObjectId
3939
from gridfs.asynchronous.grid_file import (

Diff for: test/asynchronous/test_gridfs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
sys.path[0:0] = [""]
2929

3030
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
31-
from test.utils import async_joinall, one
31+
from test.asynchronous.utils import async_joinall
32+
from test.utils_shared import one
3233

3334
import gridfs
3435
from bson.binary import Binary

Diff for: test/asynchronous/test_gridfs_bucket.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
sys.path[0:0] = [""]
3030

3131
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
32-
from test.utils import async_joinall, joinall, one
32+
from test.asynchronous.utils import async_joinall
33+
from test.utils_shared import one
3334

3435
import gridfs
3536
from bson.binary import Binary

Diff for: test/asynchronous/test_heartbeat_monitoring.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
from __future__ import annotations
1717

1818
import sys
19+
from test.asynchronous.utils import AsyncMockPool
1920

2021
sys.path[0:0] = [""]
2122

2223
from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
23-
from test.utils import AsyncMockPool, HeartbeatEventListener, async_wait_until
24+
from test.utils_shared import HeartbeatEventListener, async_wait_until
2425

2526
from pymongo.asynchronous.monitor import Monitor
2627
from pymongo.errors import ConnectionFailure

Diff for: test/asynchronous/test_index_management.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from test.asynchronous import AsyncIntegrationTest, AsyncPyMongoTestCase, unittest
3131
from test.asynchronous.unified_format import generate_test_classes
32-
from test.utils import AllowListEventListener, OvertCommandListener
32+
from test.utils_shared import AllowListEventListener, OvertCommandListener
3333

3434
from pymongo.errors import OperationFailure
3535
from pymongo.operations import SearchIndexModel

Diff for: test/asynchronous/test_load_balancer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
import threading
2424
from asyncio import Event
2525
from test.asynchronous.helpers import ConcurrentRunner, ExceptionCatchingTask
26+
from test.asynchronous.utils import async_get_pool
2627

2728
import pytest
2829

2930
sys.path[0:0] = [""]
3031

3132
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
3233
from test.asynchronous.unified_format import generate_test_classes
33-
from test.utils import (
34-
async_get_pool,
34+
from test.utils_shared import (
3535
async_wait_until,
3636
create_async_event,
3737
)

Diff for: test/asynchronous/test_max_staleness.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
sys.path[0:0] = [""]
2929

3030
from test.asynchronous import AsyncPyMongoTestCase, async_client_context, unittest
31-
from test.utils_selection_tests import create_selection_tests
31+
from test.asynchronous.utils_selection_tests import create_selection_tests
3232

3333
from pymongo.errors import ConfigurationError
3434
from pymongo.server_selectors import writable_server_selector

Diff for: test/asynchronous/test_mongos_load_balancing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from test.asynchronous import AsyncMockClientTest, async_client_context, connected, unittest
2828
from test.asynchronous.pymongo_mocks import AsyncMockClient
29-
from test.utils import async_wait_until
29+
from test.utils_shared import async_wait_until
3030

3131
from pymongo.errors import AutoReconnect, InvalidOperation
3232
from pymongo.server_selectors import writable_server_selector

Diff for: test/asynchronous/test_monitor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
sys.path[0:0] = [""]
2626

2727
from test.asynchronous import AsyncIntegrationTest, async_client_context, connected, unittest
28-
from test.utils import (
29-
ServerAndTopologyEventListener,
28+
from test.asynchronous.utils import (
3029
async_wait_until,
3130
)
31+
from test.utils_shared import ServerAndTopologyEventListener
3232

3333
from pymongo.periodic_executor import _EXECUTORS
3434

Diff for: test/asynchronous/test_monitoring.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
sanitize_cmd,
3030
unittest,
3131
)
32-
from test.utils import (
32+
from test.utils_shared import (
3333
EventListener,
3434
OvertCommandListener,
3535
async_wait_until,

Diff for: test/asynchronous/test_pooling.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import socket
2222
import sys
2323
import time
24+
from test.asynchronous.utils import async_get_pool, async_joinall
2425

2526
from bson.codec_options import DEFAULT_CODEC_OPTIONS
2627
from bson.son import SON
@@ -33,7 +34,7 @@
3334

3435
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
3536
from test.asynchronous.helpers import ConcurrentRunner
36-
from test.utils import async_get_pool, async_joinall, delay
37+
from test.utils_shared import delay
3738

3839
from pymongo.asynchronous.pool import Pool, PoolOptions
3940
from pymongo.socket_checker import SocketChecker

Diff for: test/asynchronous/test_read_concern.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sys.path[0:0] = [""]
2222

2323
from test.asynchronous import AsyncIntegrationTest, async_client_context
24-
from test.utils import OvertCommandListener
24+
from test.utils_shared import OvertCommandListener
2525

2626
from bson.son import SON
2727
from pymongo.errors import OperationFailure

0 commit comments

Comments
 (0)