Skip to content

Commit d86daba

Browse files
committed
tests: update connection test to be more specific based on PR review
1 parent 1e231a3 commit d86daba

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/test_connection.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,14 @@ def test_uri_without_credentials_doesnt_override_conn_settings(self):
411411
# OperationFailure means that mongoengine attempted authentication
412412
# w/ the provided username/password and failed - that's the desired
413413
# behavior. If the MongoDB URI would override the credentials
414-
with pytest.raises(OperationFailure):
415-
db = get_db()
416-
# pymongo 4.x does not call db.authenticate and needs to perform an operation to trigger the failure
417-
if PYMONGO_VERSION >= (4,):
414+
if PYMONGO_VERSION >= (4,):
415+
with pytest.raises(OperationFailure):
416+
db = get_db()
417+
# pymongo 4.x does not call db.authenticate and needs to perform an operation to trigger the failure
418418
db.list_collection_names()
419+
else:
420+
with pytest.raises(OperationFailure):
421+
db = get_db()
419422

420423
def test_connect_uri_with_authsource(self):
421424
"""Ensure that the connect() method works well with `authSource`

0 commit comments

Comments
 (0)