@@ -56,62 +56,39 @@ def server_host_port() -> str:
5656 return f"127.0.0.1:{ DEFAULT_FASTAPI_PORT } "
5757
5858
59- @pytest .fixture
60- def not_initialized_app (app_environment : EnvVarsDict ) -> FastAPI :
59+ def _reset_nicegui_app () -> None :
6160 # forces rebuild of middleware stack on next test
62- import importlib
6361
64- import nicegui
65- from nicegui import Client , binding , core , run
66- from nicegui . page import page
62+ # below is based on nicegui.testing.general_fixtures.nicegui_reset_globals
63+
64+ from nicegui import Client , app
6765 from starlette .routing import Route
6866
69- for route in list (nicegui . app .routes ):
67+ for route in list (app .routes ):
7068 if isinstance (route , Route ) and route .path .startswith ("/_nicegui/auto/static/" ):
71- nicegui . app .remove_route (route .path )
69+ app .remove_route (route .path )
7270
7371 all_page_routes = set (Client .page_routes .values ())
7472 all_page_routes .add ("/" )
7573 for path in all_page_routes :
76- nicegui . app .remove_route (path )
74+ app .remove_route (path )
7775
78- for route in list (nicegui . app .routes ):
76+ for route in list (app .routes ):
7977 if (
8078 isinstance (route , Route )
8179 and "{" in route .path
8280 and "}" in route .path
8381 and not route .path .startswith ("/_nicegui/" )
8482 ):
85- nicegui .app .remove_route (route .path )
86-
87- nicegui .app .openapi_schema = None
88- nicegui .app .middleware_stack = None
89- nicegui .app .user_middleware .clear ()
90- nicegui .app .urls .clear ()
91- core .air = None
92- # # NOTE favicon routes must be removed separately because they are not "pages"
93- # for route in list(nicegui.app.routes):
94- # if isinstance(route, Route) and route.path.endswith('/favicon.ico'):
95- # nicegui.app.routes.remove(route)
96-
97- importlib .reload (core )
98- importlib .reload (run )
99-
100- Client .instances .clear ()
101- Client .page_routes .clear ()
102- nicegui .app .reset ()
103-
104- # Client.auto_index_client = Client(
105- # page("/"), request=None
106- # ).__enter__() # pylint: disable=unnecessary-dunder-call
107- # Client.auto_index_client.layout.parent_slot = (
108- # None # NOTE: otherwise the layout is nested in the previous client
109- # )
110- # # NOTE we need to re-add the auto index route because we removed all routes above
111- # nicegui.app.get("/")(Client.auto_index_client.build_response)
112-
113- binding .reset ()
83+ app .remove_route (route .path )
84+
85+ app .middleware_stack = None
86+ app .user_middleware .clear ()
11487
88+
89+ @pytest .fixture
90+ def not_initialized_app (app_environment : EnvVarsDict ) -> FastAPI :
91+ _reset_nicegui_app ()
11592 return create_app ()
11693
11794
0 commit comments