Skip to content

Commit

Permalink
Merge pull request #198 from lwfitzgerald/bugfix/explicit-mongo-clien…
Browse files Browse the repository at this point in the history
…t-close

pytest-server-fixtures: Explicitly close initial Mongo client
  • Loading branch information
lwfitzgerald authored Jan 25, 2022
2 parents d02ad10 + df2eb58 commit 75e04eb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pytest-server-fixtures/pytest_server_fixtures/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def check_server_up(self):

log.info("Connecting to Mongo at %s:%s" % (self.hostname, self.port))
try:
self.api = pymongo.MongoClient(self.hostname, self.port,
serverselectiontimeoutms=200)
self.api.list_database_names()
with pymongo.MongoClient(self.hostname, self.port, serverselectiontimeoutms=200) as initial_api:
initial_api.list_database_names()

# Configure the client with default timeouts in case the server goes slow
self.api = pymongo.MongoClient(self.hostname, self.port)
return True
Expand Down

0 comments on commit 75e04eb

Please sign in to comment.