3232from tests .functional .utils import load_event
3333
3434
35+ @pytest .fixture
36+ def json_dump ():
37+ # our serializers reduce length to save on costs; fixture to replicate separators
38+ return lambda obj : json .dumps (obj , separators = ("," , ":" ))
39+
40+
3541def read_media (file_name : str ) -> bytes :
3642 path = Path (str (Path (__file__ ).parent .parent .parent .parent ) + "/docs/media/" + file_name )
3743 return path .read_bytes ()
@@ -506,13 +512,10 @@ def custom_method():
506512 assert headers ["Access-Control-Allow-Methods" ] == "CUSTOM"
507513
508514
509- def test_service_error_responses ():
515+ def test_service_error_responses (json_dump ):
510516 # SCENARIO handling different kind of service errors being raised
511517 app = ApiGatewayResolver (cors = CORSConfig ())
512518
513- def json_dump (obj ):
514- return json .dumps (obj , separators = ("," , ":" ))
515-
516519 # GIVEN an BadRequestError
517520 @app .get (rule = "/bad-request-error" , cors = False )
518521 def bad_request_error ():
@@ -641,7 +644,7 @@ def test_debug_mode_environment_variable(monkeypatch):
641644 assert app ._debug
642645
643646
644- def test_debug_json_formatting ():
647+ def test_debug_json_formatting (json_dump ):
645648 # GIVEN debug is True
646649 app = ApiGatewayResolver (debug = True )
647650 response = {"message" : "Foo" }
@@ -654,7 +657,7 @@ def foo():
654657 result = app ({"path" : "/foo" , "httpMethod" : "GET" }, None )
655658
656659 # THEN return a pretty print json in the body
657- assert result ["body" ] == json . dumps (response , indent = 4 )
660+ assert result ["body" ] == json_dump (response )
658661
659662
660663def test_debug_print_event (capsys ):
0 commit comments