Skip to content

Commit df2eb58

Browse files
committed
pytest-server-fixtures: Explicitly close initial Mongo client
When checking the Mongo server has come up properly, the `MongoTestServer` class first creates a `pymongo.MongoClient` with a short timeout to avoid waiting a long time in the failure case. After this it creates another client with the default timeouts, but prior to this change, the initial client is not closed. This change explicitly closes the initial client after use.
1 parent d02ad10 commit df2eb58

File tree

1 file changed

+3
-3
lines changed
  • pytest-server-fixtures/pytest_server_fixtures

1 file changed

+3
-3
lines changed

pytest-server-fixtures/pytest_server_fixtures/mongo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def check_server_up(self):
127127

128128
log.info("Connecting to Mongo at %s:%s" % (self.hostname, self.port))
129129
try:
130-
self.api = pymongo.MongoClient(self.hostname, self.port,
131-
serverselectiontimeoutms=200)
132-
self.api.list_database_names()
130+
with pymongo.MongoClient(self.hostname, self.port, serverselectiontimeoutms=200) as initial_api:
131+
initial_api.list_database_names()
132+
133133
# Configure the client with default timeouts in case the server goes slow
134134
self.api = pymongo.MongoClient(self.hostname, self.port)
135135
return True

0 commit comments

Comments
 (0)