Skip to content

Commit 75e04eb

Browse files
authored
Merge pull request #198 from lwfitzgerald/bugfix/explicit-mongo-client-close
pytest-server-fixtures: Explicitly close initial Mongo client
2 parents d02ad10 + df2eb58 commit 75e04eb

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)