@@ -128,9 +128,17 @@ def test_asgi_cli(monkeypatch):
128128 assert asgi_server .run .calls == [pretend .call ("0.0.0.0" , 8080 )]
129129
130130
131- def test_auto_asgi_for_aio_decorated_functions (monkeypatch ):
132- original_asgi_functions = _function_registry .ASGI_FUNCTIONS .copy ()
131+ @pytest .fixture
132+ def clean_registry ():
133+ """Save and restore function registry state."""
134+ original_asgi = _function_registry .ASGI_FUNCTIONS .copy ()
133135 _function_registry .ASGI_FUNCTIONS .clear ()
136+ yield
137+ _function_registry .ASGI_FUNCTIONS .clear ()
138+ _function_registry .ASGI_FUNCTIONS .update (original_asgi )
139+
140+
141+ def test_auto_asgi_for_aio_decorated_functions (monkeypatch , clean_registry ):
134142 _function_registry .ASGI_FUNCTIONS .add ("my_aio_func" )
135143
136144 asgi_app = pretend .stub ()
@@ -148,13 +156,8 @@ def test_auto_asgi_for_aio_decorated_functions(monkeypatch):
148156 assert create_asgi_app .calls == [pretend .call ("my_aio_func" , None , "http" )]
149157 assert asgi_server .run .calls == [pretend .call ("0.0.0.0" , 8080 )]
150158
151- _function_registry .ASGI_FUNCTIONS .clear ()
152- _function_registry .ASGI_FUNCTIONS .update (original_asgi_functions )
153-
154159
155- def test_no_auto_asgi_for_regular_functions (monkeypatch ):
156- original_asgi_functions = _function_registry .ASGI_FUNCTIONS .copy ()
157- _function_registry .ASGI_FUNCTIONS .clear ()
160+ def test_no_auto_asgi_for_regular_functions (monkeypatch , clean_registry ):
158161
159162 app = pretend .stub ()
160163 create_app = pretend .call_recorder (lambda * a , ** k : app )
@@ -169,6 +172,3 @@ def test_no_auto_asgi_for_regular_functions(monkeypatch):
169172
170173 assert create_app .calls == [pretend .call ("regular_func" , None , "http" )]
171174 assert flask_server .run .calls == [pretend .call ("0.0.0.0" , 8080 )]
172-
173- _function_registry .ASGI_FUNCTIONS .clear ()
174- _function_registry .ASGI_FUNCTIONS .update (original_asgi_functions )
0 commit comments