Skip to content

PYTHON-5259 - Better test assertions for error substrings #2253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/asynchronous/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ async def test_8_csfle_joins_qe(self):
]
)
)
self.assertTrue("not supported" in str(exc))
self.assertIn("not supported", str(exc))

@async_client_context.require_version_max(8, 1, -1)
async def test_9_error(self):
Expand Down Expand Up @@ -2721,7 +2721,7 @@ async def test_9_error(self):
]
)
)
self.assertTrue("Upgrade" in str(exc))
self.assertIn("Upgrade", str(exc))


# https://github.com/mongodb/specifications/blob/072601/source/client-side-encryption/tests/README.md#rewrap
Expand Down
14 changes: 7 additions & 7 deletions test/asynchronous/test_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async def test_csot_timeout_message(self):
with timeout(0.5):
await client.db.t.find_one({"$where": delay(2)})

self.assertTrue("(configured timeouts: timeoutMS: 500.0ms" in str(error.exception))
self.assertIn("(configured timeouts: timeoutMS: 500.0ms", str(error.exception))

@async_client_context.require_failCommand_appName
async def test_socket_timeout_message(self):
Expand All @@ -475,9 +475,9 @@ async def test_socket_timeout_message(self):
with self.assertRaises(Exception) as error:
await client.db.t.find_one({"$where": delay(2)})

self.assertTrue(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 20000.0ms)"
in str(error.exception)
self.assertIn(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 20000.0ms)",
str(error.exception),
)

@async_client_context.require_failCommand_appName
Expand Down Expand Up @@ -507,9 +507,9 @@ async def test_connection_timeout_message(self):
with self.assertRaises(Exception) as error:
await client.admin.command("ping")

self.assertTrue(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)"
in str(error.exception)
self.assertIn(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)",
str(error.exception),
)


Expand Down
2 changes: 1 addition & 1 deletion test/test_bson.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def test_unknown_type(self):
decode(bs)
except Exception as exc:
self.assertTrue(isinstance(exc, InvalidBSON))
self.assertTrue(part in str(exc))
self.assertIn(part, str(exc))
else:
self.fail("Failed to raise an exception.")

Expand Down
4 changes: 2 additions & 2 deletions test/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,7 @@ def test_8_csfle_joins_qe(self):
]
)
)
self.assertTrue("not supported" in str(exc))
self.assertIn("not supported", str(exc))

@client_context.require_version_max(8, 1, -1)
def test_9_error(self):
Expand Down Expand Up @@ -2705,7 +2705,7 @@ def test_9_error(self):
]
)
)
self.assertTrue("Upgrade" in str(exc))
self.assertIn("Upgrade", str(exc))


# https://github.com/mongodb/specifications/blob/072601/source/client-side-encryption/tests/README.md#rewrap
Expand Down
14 changes: 7 additions & 7 deletions test/test_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def test_csot_timeout_message(self):
with timeout(0.5):
client.db.t.find_one({"$where": delay(2)})

self.assertTrue("(configured timeouts: timeoutMS: 500.0ms" in str(error.exception))
self.assertIn("(configured timeouts: timeoutMS: 500.0ms", str(error.exception))

@client_context.require_failCommand_appName
def test_socket_timeout_message(self):
Expand All @@ -473,9 +473,9 @@ def test_socket_timeout_message(self):
with self.assertRaises(Exception) as error:
client.db.t.find_one({"$where": delay(2)})

self.assertTrue(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 20000.0ms)"
in str(error.exception)
self.assertIn(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 20000.0ms)",
str(error.exception),
)

@client_context.require_failCommand_appName
Expand Down Expand Up @@ -505,9 +505,9 @@ def test_connection_timeout_message(self):
with self.assertRaises(Exception) as error:
client.admin.command("ping")

self.assertTrue(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)"
in str(error.exception)
self.assertIn(
"(configured timeouts: socketTimeoutMS: 500.0ms, connectTimeoutMS: 500.0ms)",
str(error.exception),
)


Expand Down
2 changes: 1 addition & 1 deletion test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_repr(self):
hello = Hello({"ok": 1})
sd = ServerDescription(("localhost", 27017), hello)
server = Server(sd, pool=object(), monitor=object()) # type: ignore[arg-type]
self.assertTrue("Standalone" in str(server))
self.assertIn("Standalone", str(server))


if __name__ == "__main__":
Expand Down
Loading