2020# Make it optional for tests
2121try :
2222 import marshmallow_objects as mo
23+
2324 # Test that marshmallow-objects actually works with current marshmallow version
2425 # by trying to create a simple model - it fails with marshmallow 4.x
2526 class _TestModel (mo .Model ):
2627 test = mo .fields .String ()
28+
2729 _TestModel () # This will fail if incompatible
2830 MARSHMALLOW_OBJECTS_AVAILABLE = True
2931 del _TestModel
@@ -73,6 +75,7 @@ class HeadersSchema(m.Schema):
7375
7476# marshmallow-objects Model classes (only defined if library is available)
7577if MARSHMALLOW_OBJECTS_AVAILABLE :
78+
7679 class FooModel (mo .Model ):
7780 uid = mo .fields .String ()
7881 name = mo .fields .String ()
@@ -88,6 +91,7 @@ class FooListModel(mo.Model):
8891
8992 class HeadersModel (mo .Model ):
9093 name = set_data_key (field = mo .fields .String (required = True ), key = "x-name" )
94+
9195else :
9296 # Placeholders when marshmallow-objects is not available
9397 FooModel = None # type: ignore
@@ -385,9 +389,7 @@ def list_foos():
385389 resp = app .test_client ().get (path = "/foos?foo=bar" ) # missing required parameter
386390 self .assertEqual (resp .status_code , 400 )
387391
388- @parametrize (
389- "headers_cls, use_model" , _headers_cls_test_cases
390- )
392+ @parametrize ("headers_cls, use_model" , _headers_cls_test_cases )
391393 def test_validate_headers (self , headers_cls , use_model ):
392394 rebar = Rebar ()
393395 registry = rebar .create_handler_registry ()
@@ -668,9 +670,7 @@ def handler_func(foo_uid):
668670 self .assertIn ("get" , swagger ["paths" ]["/foos/{foo_uid}" ])
669671 self .assertIn ("patch" , swagger ["paths" ]["/foos/{foo_uid}" ])
670672
671- @parametrize (
672- "headers_def, use_model" , _headers_def_test_cases
673- )
673+ @parametrize ("headers_def, use_model" , _headers_def_test_cases )
674674 def test_default_headers (self , headers_def , use_model ):
675675 rebar = Rebar ()
676676 registry = rebar .create_handler_registry ()
0 commit comments