diff --git a/tests/test_config.py b/tests/test_config.py index ddf5fe3..fdfe586 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -48,8 +48,9 @@ def test_config_with_uri_in_flask_conf_var(self): mongo = flask_pymongo.PyMongo(self.app, connect=True) _wait_until_connected(mongo) - assert mongo.db is not None assert mongo.cx is not None + self.addCleanup(mongo.cx.close) + assert mongo.db is not None assert mongo.db.name == self.dbname assert ("localhost", self.port) == mongo.cx.address or ( "127.0.0.1", @@ -62,8 +63,9 @@ def test_config_with_uri_passed_directly(self): mongo = flask_pymongo.PyMongo(self.app, uri, connect=True) _wait_until_connected(mongo) - assert mongo.db is not None assert mongo.cx is not None + self.addCleanup(mongo.cx.close) + assert mongo.db is not None assert mongo.db.name == self.dbname assert ("localhost", self.port) == mongo.cx.address or ( "127.0.0.1", @@ -91,6 +93,8 @@ class CustomDict(dict[str, Any]): uri = f"mongodb://localhost:{self.port}/{self.dbname}" mongo = flask_pymongo.PyMongo(self.app, uri, document_class=CustomDict) + assert mongo.cx is not None + self.addCleanup(mongo.cx.close) assert mongo.db is not None assert mongo.db.things.find_one() is None, "precondition failed"