Skip to content

Commit d168de8

Browse files
committed
Support marshmallow 4
1 parent 91be341 commit d168de8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ docs = [
4545
"alabaster==1.0.0",
4646
]
4747
tests = [
48+
"packaging>=24.2",
4849
"pytest==8.3.5",
4950
"pytest-cov==6.0.0",
5051
"coverage==7.6.12",

tests/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.metadata
12
from collections import namedtuple
23

34
import pytest
@@ -6,8 +7,12 @@
67

78
import marshmallow as ma
89

10+
from packaging.version import Version
11+
912
from .mocks import DatabaseMock
1013

14+
MA_VERSION = Version(importlib.metadata.version("marshmallow"))
15+
1116

1217
class AppConfig:
1318
"""Base application configuration class
@@ -36,6 +41,12 @@ def app(request):
3641
return _app
3742

3843

44+
if MA_VERSION.major >= 4:
45+
pass_collection_true_kwargs = {"pass_collection": True}
46+
else:
47+
pass_collection_true_kwargs = {"pass_many": True}
48+
49+
3950
class CounterSchema(ma.Schema):
4051
"""Base Schema with load/dump counters"""
4152

@@ -50,12 +61,12 @@ def reset_load_count(cls):
5061
def reset_dump_count(cls):
5162
cls.dump_count = 0
5263

53-
@ma.post_load(pass_many=True)
64+
@ma.post_load(**pass_collection_true_kwargs)
5465
def increment_load_count(self, data, **kwargs):
5566
self.__class__.load_count += 1
5667
return data
5768

58-
@ma.post_dump(pass_many=True)
69+
@ma.post_dump(**pass_collection_true_kwargs)
5970
def increment_dump_count(self, data, **kwargs):
6071
self.__class__.dump_count += 1
6172
return data

0 commit comments

Comments
 (0)