Skip to content

Commit 077a1cb

Browse files
committed
Address review
1 parent 3f1a86c commit 077a1cb

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

.evergreen/run-tests.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,11 @@ if [ -z "$GREEN_FRAMEWORK" ]; then
285285
exit_code=$?
286286

287287
# shellcheck disable=SC2048
288-
uv run ${UV_ARGS[*]} pytest "${ASYNC_PYTEST_ARGS[@]}" "--collect-only"
289-
collected=$?
288+
uv run ${UV_ARGS[*]} pytest "${ASYNC_PYTEST_ARGS[@]}"
289+
async_exit_code=$?
290290
set -o errexit
291-
# If we collected at least one async test, run all collected tests
292-
if [ $collected -ne 5 ]; then
293-
# shellcheck disable=SC2048
294-
uv run ${UV_ARGS[*]} pytest "${ASYNC_PYTEST_ARGS[@]}"
291+
if [ $async_exit_code -ne 5 ] && [ $async_exit_code -ne 0 ]; then
292+
exit $async_exit_code
295293
fi
296294
if [ $exit_code -ne 0 ]; then
297295
exit $exit_code

test/asynchronous/pymongo_mocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async def get_async_mock_client(
166166
standalones, members, mongoses, hello_hosts, arbiters, down_hosts, *args, **kwargs
167167
)
168168

169-
if "connect" not in kwargs or "connect" in kwargs and kwargs["connect"]:
169+
if kwargs.get("connect", True):
170170
await c.aconnect()
171171
return c
172172

test/asynchronous/test_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,16 @@ class TestClientLazyConnect:
23932393

23942394
@pytest.fixture
23952395
def _get_client(self, async_rs_or_single_client):
2396-
return async_rs_or_single_client(connect=False)
2396+
clients = []
2397+
2398+
def _make_client():
2399+
client = async_rs_or_single_client(connect=False)
2400+
clients.append(client)
2401+
return client
2402+
2403+
yield _make_client
2404+
for client in clients:
2405+
client.close()
23972406

23982407
def test_insert_one(self, _get_client, async_client_context_fixture):
23992408
def reset(collection):

test/pymongo_mocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def get_mock_client(
165165
standalones, members, mongoses, hello_hosts, arbiters, down_hosts, *args, **kwargs
166166
)
167167

168-
if "connect" not in kwargs or "connect" in kwargs and kwargs["connect"]:
168+
if kwargs.get("connect", True):
169169
c._connect()
170170
return c
171171

test/test_client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,16 @@ class TestClientLazyConnect:
22972297

22982298
@pytest.fixture
22992299
def _get_client(self, rs_or_single_client):
2300-
return rs_or_single_client(connect=False)
2300+
clients = []
2301+
2302+
def _make_client():
2303+
client = rs_or_single_client(connect=False)
2304+
clients.append(client)
2305+
return client
2306+
2307+
yield _make_client
2308+
for client in clients:
2309+
client.close()
23012310

23022311
def test_insert_one(self, _get_client, client_context_fixture):
23032312
def reset(collection):

test/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ def frequent_thread_switches():
811811
sys.setswitchinterval(interval)
812812

813813

814-
def lazy_client_trial(reset, target, test, client, client_context):
814+
def lazy_client_trial(reset, target, test, get_client, client_context):
815815
"""Test concurrent operations on a lazily-connecting client.
816816
817817
`reset` takes a collection and resets it for the next trial.
@@ -827,7 +827,7 @@ def lazy_client_trial(reset, target, test, client, client_context):
827827
with frequent_thread_switches():
828828
for _i in range(NTRIALS):
829829
reset(collection)
830-
lazy_client = client
830+
lazy_client = get_client()
831831
lazy_collection = lazy_client.pymongo_test.test
832832
run_threads(lazy_collection, target)
833833
test(lazy_collection)

0 commit comments

Comments
 (0)