From ffc58ef80e6197beac723e4fab34bde0b70111be Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 17 Jul 2024 19:54:52 +0200 Subject: [PATCH] MongoDB/PyMongo: Fix tests about result ordering Because the `ordered` option of `insert_many` is not being honored yet, the result order of returned documents is indeterministic. Using `.sort("_id", pymongo.ASCENDING)` does not improve the situation. --- tests/adapter/test_pymongo.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/adapter/test_pymongo.py b/tests/adapter/test_pymongo.py index 34f7f537..88cff954 100644 --- a/tests/adapter/test_pymongo.py +++ b/tests/adapter/test_pymongo.py @@ -302,24 +302,26 @@ def test_pymongo_tutorial( # Querying for More Than One Document. # https://pymongo.readthedocs.io/en/stable/tutorial.html#querying-for-more-than-one-document - assert list(posts.find({"author": "Mike"})) == [ - { + # TODO: Because the `ordered` option of `insert_many` is not being honored yet, + # the result order of returned documents is indeterministic. + # Using `.sort("_id", pymongo.ASCENDING)` does not improve the situation. + results = list(posts.find({"author": "Mike"})) + assert { "author": "Mike", "text": "My first blog post!", "tags": mock.ANY, "date": mock.ANY, "title": mock.ANY, "_id": mock.ANY, - }, - { + } in results + assert { "author": "Mike", "text": "Another post!", "tags": mock.ANY, "date": mock.ANY, "title": mock.ANY, "_id": mock.ANY, - }, - ] + } in results # Counting. # https://pymongo.readthedocs.io/en/stable/tutorial.html#counting