Skip to content

Commit ae650e0

Browse files
committed
Asynchronous test_client.py done
1 parent cca705d commit ae650e0

File tree

3 files changed

+482
-28
lines changed

3 files changed

+482
-28
lines changed

test/asynchronous/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,19 @@
1515
"""Asynchronous test suite for pymongo, bson, and gridfs."""
1616
from __future__ import annotations
1717

18-
import asyncio
1918
import gc
20-
import logging
2119
import multiprocessing
2220
import os
2321
import signal
2422
import socket
2523
import subprocess
2624
import sys
27-
import threading
2825
import time
29-
import traceback
3026
import unittest
3127
import warnings
3228
from asyncio import iscoroutinefunction
3329

34-
import pytest_asyncio
35-
from pymongo.lock import _create_lock, _async_create_lock
30+
from pymongo.lock import _async_create_lock
3631

3732
from test.helpers import (
3833
COMPRESSORS,

test/asynchronous/conftest.py

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import asyncio
4-
import contextlib
54
import sys
65
from typing import Callable
76

@@ -17,6 +16,7 @@
1716
import pytest
1817
import pytest_asyncio
1918

19+
from test.asynchronous.pymongo_mocks import AsyncMockClient
2020
from test.utils import FunctionCallRecorder
2121

2222
_IS_SYNC = False
@@ -157,11 +157,17 @@ async def _async_mongo_client(
157157
return client
158158

159159

160-
async def async_single_client_noauth(
161-
async_client_context, h: Any = None, p: Any = None, **kwargs: Any
162-
) -> AsyncMongoClient[dict]:
160+
@pytest_asyncio.fixture(loop_scope="session")
161+
async def async_single_client_noauth(async_client_context_fixture) -> Callable[..., AsyncMongoClient]:
163162
"""Make a direct connection. Don't authenticate."""
164-
return await _async_mongo_client(async_client_context, h, p, authenticate=False, directConnection=True, **kwargs)
163+
clients = []
164+
async def _make_client(h: Any = None, p: Any = None, **kwargs: Any):
165+
client = await _async_mongo_client(async_client_context_fixture, h, p, authenticate=False, directConnection=True, **kwargs)
166+
clients.append(client)
167+
return client
168+
yield _make_client
169+
for client in clients:
170+
await client.close()
165171

166172
@pytest_asyncio.fixture(loop_scope="session")
167173
async def async_single_client(async_client_context_fixture) -> Callable[..., AsyncMongoClient]:
@@ -175,13 +181,18 @@ async def _make_client(h: Any = None, p: Any = None, **kwargs: Any):
175181
for client in clients:
176182
await client.close()
177183

178-
# @pytest_asyncio.fixture(loop_scope="function")
179-
# async def async_rs_client_noauth(
180-
# async_client_context, h: Any = None, p: Any = None, **kwargs: Any
181-
# ) -> AsyncMongoClient[dict]:
182-
# """Connect to the replica set. Don't authenticate."""
183-
# return await _async_mongo_client(async_client_context, h, p, authenticate=False, **kwargs)
184-
#
184+
@pytest_asyncio.fixture(loop_scope="session")
185+
async def async_rs_client_noauth(async_client_context_fixture) -> Callable[..., AsyncMongoClient]:
186+
"""Connect to the replica set. Don't authenticate."""
187+
clients = []
188+
async def _make_client(h: Any = None, p: Any = None, **kwargs: Any):
189+
client = await _async_mongo_client(async_client_context_fixture, h, p, authenticate=False, **kwargs)
190+
clients.append(client)
191+
return client
192+
yield _make_client
193+
for client in clients:
194+
await client.close()
195+
185196

186197
@pytest_asyncio.fixture(loop_scope="session")
187198
async def async_rs_client(async_client_context_fixture) -> Callable[..., AsyncMongoClient]:
@@ -250,6 +261,23 @@ def patch_resolver():
250261
yield patched_resolver
251262
pymongo.srv_resolver._resolve = _resolve
252263

253-
264+
@pytest_asyncio.fixture(loop_scope="session")
265+
async def async_mock_client():
266+
clients = []
267+
268+
async def _make_client(standalones,
269+
members,
270+
mongoses,
271+
hello_hosts=None,
272+
arbiters=None,
273+
down_hosts=None,
274+
*args,
275+
**kwargs):
276+
client = await AsyncMockClient.get_async_mock_client(standalones, members, mongoses, hello_hosts, arbiters, down_hosts, *args, **kwargs)
277+
clients.append(client)
278+
return client
279+
yield _make_client
280+
for client in clients:
281+
await client.close()
254282

255283
pytest_collection_modifyitems = pytest_conf.pytest_collection_modifyitems

0 commit comments

Comments
 (0)