Skip to content

PYTHON-5113 - Refactor test utils for async #2149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/asynchronous/test_async_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

import asyncio
import sys
from test.utils import async_get_pool, delay, one
from test.asynchronous.utils import async_get_pool
from test.utils_shared import delay, one

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

Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
async_client_context,
unittest,
)
from test.utils import AllowListEventListener, delay, ignore_deprecations
from test.utils_shared import AllowListEventListener, delay, ignore_deprecations

import pytest

Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
sys.path[0:0] = [""]

from test.asynchronous import AsyncIntegrationTest, async_client_context, remove_all_users, unittest
from test.utils import async_wait_until
from test.utils_shared import async_wait_until

from bson.binary import Binary, UuidRepresentation
from bson.codec_options import CodecOptions
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_change_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
unittest,
)
from test.asynchronous.unified_format import generate_test_classes
from test.utils import (
from test.utils_shared import (
AllowListEventListener,
EventListener,
OvertCommandListener,
Expand Down
10 changes: 6 additions & 4 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@
unittest,
)
from test.asynchronous.pymongo_mocks import AsyncMockClient
from test.asynchronous.utils import (
async_get_pool,
async_wait_until,
asyncAssertRaisesExactly,
)
from test.test_binary import BinaryData
from test.utils import (
from test.utils_shared import (
NTHREADS,
CMAPListener,
FunctionCallRecorder,
async_get_pool,
async_wait_until,
asyncAssertRaisesExactly,
delay,
gevent_monkey_patched,
is_greenthread_patched,
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_client_bulk_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
async_client_context,
unittest,
)
from test.utils import (
from test.utils_shared import (
OvertCommandListener,
)
from unittest.mock import patch
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_collation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import functools
import warnings
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.utils import EventListener, OvertCommandListener
from test.utils_shared import EventListener, OvertCommandListener
from typing import Any

from pymongo.asynchronous.helpers import anext
Expand Down
5 changes: 2 additions & 3 deletions test/asynchronous/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import sys
from codecs import utf_8_decode
from collections import defaultdict
from test.asynchronous.utils import async_get_pool, async_is_mongos
from typing import Any, Iterable, no_type_check

from pymongo.asynchronous.database import AsyncDatabase
Expand All @@ -33,12 +34,10 @@
AsyncUnitTest,
async_client_context,
)
from test.utils import (
from test.utils_shared import (
IMPOSSIBLE_WRITE_CONCERN,
EventListener,
OvertCommandListener,
async_get_pool,
async_is_mongos,
async_wait_until,
)

Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
sys.path[0:0] = [""]
from asyncio import iscoroutinefunction
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.utils import OvertCommandListener
from test.utils_shared import OvertCommandListener

from bson.dbref import DBRef
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import asyncio
import time
from test.asynchronous import AsyncIntegrationTest, async_client_context
from test.utils import delay
from test.utils_shared import delay

_IS_SYNC = False

Expand Down
8 changes: 3 additions & 5 deletions test/asynchronous/test_connection_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
import sys
import time
from pathlib import Path
from test.asynchronous.utils import async_get_pool, async_get_pools

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

from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
from test.asynchronous import AsyncIntegrationTest, async_client_context, client_knobs, unittest
from test.asynchronous.pymongo_mocks import DummyMonitor
from test.asynchronous.utils_spec_runner import AsyncSpecTestCreator, SpecRunnerTask
from test.utils import (
from test.utils_shared import (
CMAPListener,
async_client_context,
async_get_pool,
async_get_pools,
async_wait_until,
camel_to_snake,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from __future__ import annotations

import sys
from test.asynchronous.utils import async_ensure_all_connected

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

Expand All @@ -25,9 +26,8 @@
unittest,
)
from test.asynchronous.helpers import async_repl_set_step_down
from test.utils import (
from test.utils_shared import (
CMAPListener,
async_ensure_all_connected,
)

from bson import SON
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
sys.path[0:0] = [""]

from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.utils import (
from test.utils_shared import (
AllowListEventListener,
EventListener,
OvertCommandListener,
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_data_lake.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from test.asynchronous import AsyncIntegrationTest, AsyncUnitTest, async_client_context, unittest
from test.asynchronous.unified_format import generate_test_classes
from test.utils import (
from test.utils_shared import (
OvertCommandListener,
)

Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from test import unittest
from test.asynchronous import AsyncIntegrationTest, async_client_context
from test.test_custom_types import DECIMAL_CODECOPTS
from test.utils import (
from test.utils_shared import (
IMPOSSIBLE_WRITE_CONCERN,
OvertCommandListener,
async_wait_until,
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
async_client_context,
unittest,
)
from test.utils import async_wait_until
from test.utils_shared import async_wait_until

from pymongo.common import validate_read_preference_tags
from pymongo.errors import ConfigurationError
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
KMIP_CREDS,
LOCAL_MASTER_KEY,
)
from test.utils import (
from test.utils_shared import (
AllowListEventListener,
OvertCommandListener,
TopologyEventListener,
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
sys.path[0:0] = [""]

from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.utils import async_wait_until
from test.utils_shared import async_wait_until

import pymongo
from pymongo.asynchronous.helpers import anext
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_grid_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

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

from test.utils import OvertCommandListener
from test.utils_shared import OvertCommandListener

from bson.objectid import ObjectId
from gridfs.asynchronous.grid_file import (
Expand Down
3 changes: 2 additions & 1 deletion test/asynchronous/test_gridfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
sys.path[0:0] = [""]

from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.utils import async_joinall, one
from test.asynchronous.utils import async_joinall
from test.utils_shared import one

import gridfs
from bson.binary import Binary
Expand Down
3 changes: 2 additions & 1 deletion test/asynchronous/test_gridfs_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
sys.path[0:0] = [""]

from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.utils import async_joinall, joinall, one
from test.asynchronous.utils import async_joinall
from test.utils_shared import one

import gridfs
from bson.binary import Binary
Expand Down
3 changes: 2 additions & 1 deletion test/asynchronous/test_heartbeat_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
from __future__ import annotations

import sys
from test.asynchronous.utils import AsyncMockPool

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

from test.asynchronous import AsyncIntegrationTest, client_knobs, unittest
from test.utils import AsyncMockPool, HeartbeatEventListener, async_wait_until
from test.utils_shared import HeartbeatEventListener, async_wait_until

from pymongo.asynchronous.monitor import Monitor
from pymongo.errors import ConnectionFailure
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_index_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from test.asynchronous import AsyncIntegrationTest, AsyncPyMongoTestCase, unittest
from test.asynchronous.unified_format import generate_test_classes
from test.utils import AllowListEventListener, OvertCommandListener
from test.utils_shared import AllowListEventListener, OvertCommandListener

from pymongo.errors import OperationFailure
from pymongo.operations import SearchIndexModel
Expand Down
4 changes: 2 additions & 2 deletions test/asynchronous/test_load_balancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import threading
from asyncio import Event
from test.asynchronous.helpers import ConcurrentRunner, ExceptionCatchingTask
from test.asynchronous.utils import async_get_pool

import pytest

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

from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.asynchronous.unified_format import generate_test_classes
from test.utils import (
async_get_pool,
from test.utils_shared import (
async_wait_until,
create_async_event,
)
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_max_staleness.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
sys.path[0:0] = [""]

from test.asynchronous import AsyncPyMongoTestCase, async_client_context, unittest
from test.utils_selection_tests import create_selection_tests
from test.asynchronous.utils_selection_tests import create_selection_tests

from pymongo.errors import ConfigurationError
from pymongo.server_selectors import writable_server_selector
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_mongos_load_balancing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from test.asynchronous import AsyncMockClientTest, async_client_context, connected, unittest
from test.asynchronous.pymongo_mocks import AsyncMockClient
from test.utils import async_wait_until
from test.utils_shared import async_wait_until

from pymongo.errors import AutoReconnect, InvalidOperation
from pymongo.server_selectors import writable_server_selector
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
sanitize_cmd,
unittest,
)
from test.utils import (
from test.utils_shared import (
EventListener,
OvertCommandListener,
async_wait_until,
Expand Down
3 changes: 2 additions & 1 deletion test/asynchronous/test_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import socket
import sys
import time
from test.asynchronous.utils import async_get_pool, async_joinall

from bson.codec_options import DEFAULT_CODEC_OPTIONS
from bson.son import SON
Expand All @@ -33,7 +34,7 @@

from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.asynchronous.helpers import ConcurrentRunner
from test.utils import async_get_pool, async_joinall, delay
from test.utils_shared import delay

from pymongo.asynchronous.pool import Pool, PoolOptions
from pymongo.socket_checker import SocketChecker
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_read_concern.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sys.path[0:0] = [""]

from test.asynchronous import AsyncIntegrationTest, async_client_context
from test.utils import OvertCommandListener
from test.utils_shared import OvertCommandListener

from bson.son import SON
from pymongo.errors import OperationFailure
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_read_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
connected,
unittest,
)
from test.utils import (
from test.utils_shared import (
OvertCommandListener,
async_wait_until,
one,
Expand Down
2 changes: 1 addition & 1 deletion test/asynchronous/test_read_write_concern_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
from test.asynchronous.unified_format import generate_test_classes
from test.utils import OvertCommandListener
from test.utils_shared import OvertCommandListener

from pymongo import DESCENDING
from pymongo.asynchronous.mongo_client import AsyncMongoClient
Expand Down
4 changes: 2 additions & 2 deletions test/asynchronous/test_retryable_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import pprint
import sys
import threading
from test.asynchronous.utils import async_set_fail_point

from pymongo.errors import AutoReconnect

Expand All @@ -31,10 +32,9 @@
client_knobs,
unittest,
)
from test.utils import (
from test.utils_shared import (
CMAPListener,
OvertCommandListener,
async_set_fail_point,
)

from pymongo.monitoring import (
Expand Down
4 changes: 2 additions & 2 deletions test/asynchronous/test_retryable_writes.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pprint
import sys
import threading
from test.asynchronous.utils import async_set_fail_point

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

Expand All @@ -30,12 +31,11 @@
unittest,
)
from test.asynchronous.helpers import client_knobs
from test.utils import (
from test.utils_shared import (
CMAPListener,
DeprecationFilter,
EventListener,
OvertCommandListener,
async_set_fail_point,
)
from test.version import Version

Expand Down
Loading
Loading