From f6c209a8585e7bc8ea1bbfc3135152d2b1196d56 Mon Sep 17 00:00:00 2001 From: Alexander van Eck Date: Tue, 30 Apr 2024 11:31:52 +0200 Subject: [PATCH 1/5] deps: Add `motor` 4.x compatibility. Fixes #386 and #278 --- HISTORY.rst | 9 +++++++++ azure-pipelines.yml | 9 ++++++--- setup.py | 2 +- tox.ini | 5 +++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 3d665110..9ee4ae6b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,6 +2,15 @@ History ======= +3.2.0 (2024-04-30) +------------------ + +Features: + +* Add compatibility with `pymongo` 4.0. +* Allow `motor` 4.0 dependency so that `pymongo` 4.x dependency can be used. + + 3.1.0 (2021-12-23) ------------------ diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 223868ea..725976c7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,7 +25,8 @@ stages: parameters: toxenvs: - py39-pymongo - - py39-motor + - py39-motor2 + - py39-motor3 - py39-txmongo coverage: true pre_test: @@ -44,10 +45,12 @@ stages: parameters: toxenvs: - py37-pymongo - - py37-motor + - py37-motor2 + - py37-motor3 - py37-txmongo - py39-pymongo - - py39-motor + - py39-motor2 + - py39-motor3 - py39-txmongo coverage: true pre_test: diff --git a/setup.py b/setup.py index aa5b05c3..1aab81cf 100755 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ python_requires='>=3.7', install_requires=requirements, extras_require={ - 'motor': ['motor>=2.0,<3.0'], + 'motor': ['motor>=2.0,<4.0'], 'txmongo': ['txmongo>=19.2.0'], 'mongomock': ['mongomock'], }, diff --git a/tox.ini b/tox.ini index 1e2248a6..c57ddf88 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = lint,{py37,py38,py39}-{motor,pymongo,txmongo} +envlist = lint,{py37,py38,py39}-{motor2,motor3,pymongo,txmongo} [testenv] setenv = @@ -7,7 +7,8 @@ setenv = deps = pytest>=4.0.0 coverage>=5.3.0 - motor: motor>=2.0,<3.0 + motor2: motor>=2.0,<3.0 + motor3: motor>=3.0,<4.0 pymongo: mongomock>=3.5.0 txmongo: pymongo<3.11 txmongo: txmongo>=19.2.0 From cd74004d7b64adabdc0c98d945b7436e0835a85e Mon Sep 17 00:00:00 2001 From: Alexander van Eck Date: Tue, 30 Apr 2024 11:50:43 +0200 Subject: [PATCH 2/5] test: Rename `setup()` to `setup_method()` to execute for every TestCase. This behavior was changed in pytest 7.0 where `setup()` is now only executed once when the class loads. --- tests/common.py | 4 ++-- tests/test_document.py | 4 ++-- tests/test_marshmallow.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/common.py b/tests/common.py index 047143b3..7e598d14 100644 --- a/tests/common.py +++ b/tests/common.py @@ -71,13 +71,13 @@ def is_compatible_with(db): class BaseTest: - def setup(self): + def setup_method(self): self.instance = MockedInstance(MockedDB('my_moked_db')) class BaseDBTest: - def setup(self): + def setup_method(self): con.drop_database(TEST_DB) diff --git a/tests/test_document.py b/tests/test_document.py index fb268a9a..c786c879 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -36,8 +36,8 @@ class Meta: class TestDocument(BaseTest): - def setup(self): - super().setup() + def setup_method(self): + super().setup_method() self.instance.register(BaseStudent) self.Student = self.instance.register(Student) self.EasyIdStudent = self.instance.register(EasyIdStudent) diff --git a/tests/test_marshmallow.py b/tests/test_marshmallow.py index c3748b61..4bf67306 100644 --- a/tests/test_marshmallow.py +++ b/tests/test_marshmallow.py @@ -21,8 +21,8 @@ def teardown_method(self, method): # Reset i18n config before each test set_gettext(None) - def setup(self): - super().setup() + def setup_method(self): + super().setup_method() class User(Document): name = fields.StrField() From f382410acb80ab787b1f1eb30c467a8c4315b491 Mon Sep 17 00:00:00 2001 From: Alexander van Eck Date: Tue, 30 Apr 2024 11:51:42 +0200 Subject: [PATCH 3/5] style: assert type with `is` instead of `==`. --- tests/test_embedded_document.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_embedded_document.py b/tests/test_embedded_document.py index 5323c0fb..59edc376 100644 --- a/tests/test_embedded_document.py +++ b/tests/test_embedded_document.py @@ -60,7 +60,7 @@ class MyDoc(Document): d.from_mongo(data={'in_mongo_embedded': {'in_mongo_a': 1, 'b': 2}}) assert d.dump() == {'embedded': {'a': 1, 'b': 2}} embedded = d.get('embedded') - assert type(embedded) == MyEmbeddedDocument + assert type(embedded) is MyEmbeddedDocument assert embedded.a == 1 assert embedded.b == 2 assert embedded.dump() == {'a': 1, 'b': 2} From fe968f7f5c0b4a33a1122d499510b527414c4ad5 Mon Sep 17 00:00:00 2001 From: Alexander van Eck Date: Tue, 30 Apr 2024 12:08:09 +0200 Subject: [PATCH 4/5] test: Assert `Deferred` instead of potential Attribute error. In older versions of `pymongo` attributes of Deferred would be None, in newer versions they raise AttributeError. --- tests/frameworks/test_txmongo.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/frameworks/test_txmongo.py b/tests/frameworks/test_txmongo.py index 98c4b043..74eea77c 100644 --- a/tests/frameworks/test_txmongo.py +++ b/tests/frameworks/test_txmongo.py @@ -289,9 +289,9 @@ def test_reference(self, classroom_model): assert teacher_fetched.name == 'Dr. Brown' teacher_fetched = yield course.teacher.fetch(force_reload=True) assert teacher_fetched.name == 'M. Strickland' - # Test fetch with projection - assert course.teacher.fetch(projection={'has_apple': 0}, - force_reload=True).has_apple is None + # Test fetch with projection, without `yield`. + teacher_fetched = course.teacher.fetch(projection={'has_apple': 0}, force_reload=True) + assert isinstance(teacher_fetched, Deferred) # Test bad ref as well course.teacher = Reference(classroom_model.Teacher, ObjectId()) with pytest.raises(ma.ValidationError) as exc: From 8d755cba023cae6f6e58ff48cc95e1a95e0a9b41 Mon Sep 17 00:00:00 2001 From: Alexander van Eck Date: Tue, 30 Apr 2024 12:09:16 +0200 Subject: [PATCH 5/5] test: Add pymongo 3.x and pymongo 4.x to test matrix --- tox.ini | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index c57ddf88..2f4f9cb5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = lint,{py37,py38,py39}-{motor2,motor3,pymongo,txmongo} +envlist = lint,{py37,py38,py39}-{motor2,motor3,pymongo3,pymongo4,txmongo} [testenv] setenv = @@ -9,7 +9,10 @@ deps = coverage>=5.3.0 motor2: motor>=2.0,<3.0 motor3: motor>=3.0,<4.0 - pymongo: mongomock>=3.5.0 + pymongo3: pymongo>3,<4 + pymongo3: mongomock>=3.5.0 + pymongo4: pymongo>4,<5 + pymongo4: mongomock>=3.5.0 txmongo: pymongo<3.11 txmongo: txmongo>=19.2.0 txmongo: pytest-twisted>=1.12