Skip to content

Commit adf0504

Browse files
committed
mutate client context to reset it
1 parent cebbd6f commit adf0504

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

test/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def __init__(self):
127127
server_api = ServerApi(MONGODB_API_VERSION)
128128
self.default_client_options["server_api"] = server_api
129129

130+
def reset(self):
131+
self.__init__()
132+
130133
@property
131134
def client_options(self):
132135
"""Return the MongoClient options for creating a duplicate client."""
@@ -859,13 +862,12 @@ def max_message_size_bytes(self):
859862
client_context = ClientContext()
860863

861864

862-
def recreate_client_context():
865+
def reset_client_context():
863866
if _IS_SYNC:
864867
# sync tests don't need to recreate a client context
865868
return
866-
global client_context
867869
teardown()
868-
client_context = ClientContext()
870+
client_context.reset()
869871
setup()
870872

871873

test/asynchronous/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def __init__(self):
127127
server_api = ServerApi(MONGODB_API_VERSION)
128128
self.default_client_options["server_api"] = server_api
129129

130+
def reset(self):
131+
self.__init__()
132+
130133
@property
131134
def client_options(self):
132135
"""Return the MongoClient options for creating a duplicate client."""
@@ -861,13 +864,12 @@ async def max_message_size_bytes(self):
861864
async_client_context = AsyncClientContext()
862865

863866

864-
async def recreate_client_context():
867+
async def reset_client_context():
865868
if _IS_SYNC:
866869
# sync tests don't need to recreate a client context
867870
return
868-
global async_client_context
869871
await async_teardown()
870-
async_client_context = AsyncClientContext()
872+
async_client_context.reset()
871873
await async_setup()
872874

873875

test/asynchronous/test_connections_survive_primary_stepdown_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from test.asynchronous import (
2323
AsyncIntegrationTest,
2424
async_client_context,
25-
recreate_client_context,
25+
reset_client_context,
2626
unittest,
2727
)
2828
from test.asynchronous.helpers import async_repl_set_step_down
@@ -65,7 +65,7 @@ async def _setup_class(cls):
6565
@classmethod
6666
async def _tearDown_class(cls):
6767
await cls.client.close()
68-
await recreate_client_context()
68+
await reset_client_context()
6969

7070
async def asyncSetUp(self):
7171
# Note that all ops use same write-concern as self.db (majority).

test/test_connections_survive_primary_stepdown_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from test import (
2323
IntegrationTest,
2424
client_context,
25-
recreate_client_context,
25+
reset_client_context,
2626
unittest,
2727
)
2828
from test.helpers import repl_set_step_down
@@ -65,7 +65,7 @@ def _setup_class(cls):
6565
@classmethod
6666
def _tearDown_class(cls):
6767
cls.client.close()
68-
recreate_client_context()
68+
reset_client_context()
6969

7070
def setUp(self):
7171
# Note that all ops use same write-concern as self.db (majority).

test/test_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
wait_until,
3030
)
3131

32-
from pymongo.synchronous.periodic_executor import _EXECUTORS
32+
from pymongo.periodic_executor import _EXECUTORS
3333

3434

3535
def unregistered(ref):

0 commit comments

Comments
 (0)