Skip to content

Commit 5b49ba5

Browse files
committed
fix task teardown
1 parent f72727c commit 5b49ba5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/test_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ def test_config_with_uri_in_flask_conf_var(self):
4848
mongo = flask_pymongo.PyMongo(self.app, connect=True)
4949

5050
_wait_until_connected(mongo)
51-
assert mongo.db is not None
5251
assert mongo.cx is not None
52+
self.addCleanup(mongo.cx.close)
53+
assert mongo.db is not None
5354
assert mongo.db.name == self.dbname
5455
assert ("localhost", self.port) == mongo.cx.address or (
5556
"127.0.0.1",
@@ -62,8 +63,9 @@ def test_config_with_uri_passed_directly(self):
6263
mongo = flask_pymongo.PyMongo(self.app, uri, connect=True)
6364

6465
_wait_until_connected(mongo)
65-
assert mongo.db is not None
6666
assert mongo.cx is not None
67+
self.addCleanup(mongo.cx.close)
68+
assert mongo.db is not None
6769
assert mongo.db.name == self.dbname
6870
assert ("localhost", self.port) == mongo.cx.address or (
6971
"127.0.0.1",
@@ -91,6 +93,8 @@ class CustomDict(dict[str, Any]):
9193

9294
uri = f"mongodb://localhost:{self.port}/{self.dbname}"
9395
mongo = flask_pymongo.PyMongo(self.app, uri, document_class=CustomDict)
96+
assert mongo.cx is not None
97+
self.addCleanup(mongo.cx.close)
9498
assert mongo.db is not None
9599
assert mongo.db.things.find_one() is None, "precondition failed"
96100

0 commit comments

Comments
 (0)