2525
2626import pytest
2727
28- from pymongo import AsyncMongoClient , MongoClient
28+ from pymongo import AsyncMongoClient
2929from pymongo .driver_info import DriverInfo
3030from pymongo .monitoring import ConnectionClosedEvent
3131
@@ -67,7 +67,7 @@ def respond(r):
6767 if "ismaster" in r :
6868 # then this is a handshake request
6969 self .handshake_req = r
70- return r .reply (OpMsgReply (minWireVersion = 0 , maxWireVersion = 13 ))
70+ return r .reply (OpMsgReply (maxWireVersion = 13 ))
7171
7272 self .server .autoresponds (respond )
7373 self .server .run ()
@@ -124,79 +124,71 @@ async def check_metadata_added(
124124 self .assertEqual (metadata , new_metadata )
125125
126126 async def test_append_metadata (self ):
127- client = AsyncMongoClient (
127+ client = await self . async_rs_or_single_client (
128128 "mongodb://" + self .server .address_string ,
129129 maxIdleTimeMS = 1 ,
130130 driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
131131 )
132132 await self .check_metadata_added (client , "framework" , "2.0" , "Framework Platform" )
133- await client .close ()
134133
135134 async def test_append_metadata_platform_none (self ):
136- client = AsyncMongoClient (
135+ client = await self . async_rs_or_single_client (
137136 "mongodb://" + self .server .address_string ,
138137 maxIdleTimeMS = 1 ,
139138 driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
140139 )
141140 await self .check_metadata_added (client , "framework" , "2.0" , None )
142- await client .close ()
143141
144142 async def test_append_metadata_version_none (self ):
145- client = AsyncMongoClient (
143+ client = await self . async_rs_or_single_client (
146144 "mongodb://" + self .server .address_string ,
147145 maxIdleTimeMS = 1 ,
148146 driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
149147 )
150148 await self .check_metadata_added (client , "framework" , None , "Framework Platform" )
151- await client .close ()
152149
153150 async def test_append_metadata_platform_version_none (self ):
154- client = AsyncMongoClient (
151+ client = await self . async_rs_or_single_client (
155152 "mongodb://" + self .server .address_string ,
156153 maxIdleTimeMS = 1 ,
157154 driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
158155 )
159156 await self .check_metadata_added (client , "framework" , None , None )
160- await client .close ()
161157
162158 async def test_multiple_successive_metadata_updates (self ):
163- client = AsyncMongoClient (
159+ client = await self . async_rs_or_single_client (
164160 "mongodb://" + self .server .address_string , maxIdleTimeMS = 1 , connect = False
165161 )
166162 client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
167163 await self .check_metadata_added (client , "framework" , "2.0" , "Framework Platform" )
168- await client .close ()
169164
170165 async def test_multiple_successive_metadata_updates_platform_none (self ):
171- client = AsyncMongoClient (
166+ client = await self . async_rs_or_single_client (
172167 "mongodb://" + self .server .address_string ,
173168 maxIdleTimeMS = 1 ,
174169 )
175170 client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
176171 await self .check_metadata_added (client , "framework" , "2.0" , None )
177- await client .close ()
178172
179173 async def test_multiple_successive_metadata_updates_version_none (self ):
180- client = AsyncMongoClient (
174+ client = await self . async_rs_or_single_client (
181175 "mongodb://" + self .server .address_string ,
182176 maxIdleTimeMS = 1 ,
183177 )
184178 client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
185179 await self .check_metadata_added (client , "framework" , None , "Framework Platform" )
186- await client .close ()
187180
188181 async def test_multiple_successive_metadata_updates_platform_version_none (self ):
189- client = AsyncMongoClient (
182+ client = await self . async_rs_or_single_client (
190183 "mongodb://" + self .server .address_string ,
191184 maxIdleTimeMS = 1 ,
192185 )
193186 client .append_metadata (DriverInfo ("library" , "1.2" , "Library Platform" ))
194187 await self .check_metadata_added (client , "framework" , None , None )
195- await client .close ()
196188
197189 async def test_doesnt_update_established_connections (self ):
198190 listener = CMAPListener ()
199- client = AsyncMongoClient (
191+ client = await self . async_rs_or_single_client (
200192 "mongodb://" + self .server .address_string ,
201193 maxIdleTimeMS = 1 ,
202194 driver = DriverInfo ("library" , "1.2" , "Library Platform" ),
@@ -218,8 +210,6 @@ async def test_doesnt_update_established_connections(self):
218210 self .assertIsNone (self .handshake_req )
219211 self .assertEqual (listener .event_count (ConnectionClosedEvent ), 0 )
220212
221- await client .close ()
222-
223213
224214if __name__ == "__main__" :
225215 unittest .main ()
0 commit comments