do not clear all decorated pages during AppHarness tests (#3093)
This commit is contained in:
parent
aff0eb664e
commit
3014db1c1c
@ -124,6 +124,7 @@ class AppHarness:
|
|||||||
backend: Optional[uvicorn.Server] = None
|
backend: Optional[uvicorn.Server] = None
|
||||||
state_manager: Optional[StateManagerMemory | StateManagerRedis] = None
|
state_manager: Optional[StateManagerMemory | StateManagerRedis] = None
|
||||||
_frontends: list["WebDriver"] = dataclasses.field(default_factory=list)
|
_frontends: list["WebDriver"] = dataclasses.field(default_factory=list)
|
||||||
|
_decorated_pages: list = dataclasses.field(default_factory=list)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
@ -230,11 +231,15 @@ class AppHarness:
|
|||||||
with chdir(self.app_path):
|
with chdir(self.app_path):
|
||||||
# ensure config and app are reloaded when testing different app
|
# ensure config and app are reloaded when testing different app
|
||||||
reflex.config.get_config(reload=True)
|
reflex.config.get_config(reload=True)
|
||||||
# Clean out any `rx.page` decorators from other tests.
|
# Save decorated pages before importing the test app module
|
||||||
reflex.app.DECORATED_PAGES.clear()
|
before_decorated_pages = reflex.app.DECORATED_PAGES.copy()
|
||||||
# Ensure the AppHarness test does not skip State assignment due to running via pytest
|
# Ensure the AppHarness test does not skip State assignment due to running via pytest
|
||||||
os.environ.pop(reflex.constants.PYTEST_CURRENT_TEST, None)
|
os.environ.pop(reflex.constants.PYTEST_CURRENT_TEST, None)
|
||||||
self.app_module = reflex.utils.prerequisites.get_compiled_app(reload=True)
|
self.app_module = reflex.utils.prerequisites.get_compiled_app(reload=True)
|
||||||
|
# Save the pages that were added during testing
|
||||||
|
self._decorated_pages = [
|
||||||
|
p for p in reflex.app.DECORATED_PAGES if p not in before_decorated_pages
|
||||||
|
]
|
||||||
self.app_instance = self.app_module.app
|
self.app_instance = self.app_module.app
|
||||||
if isinstance(self.app_instance._state_manager, StateManagerRedis):
|
if isinstance(self.app_instance._state_manager, StateManagerRedis):
|
||||||
# Create our own redis connection for testing.
|
# Create our own redis connection for testing.
|
||||||
@ -396,6 +401,10 @@ class AppHarness:
|
|||||||
for driver in self._frontends:
|
for driver in self._frontends:
|
||||||
driver.quit()
|
driver.quit()
|
||||||
|
|
||||||
|
# Cleanup decorated pages added during testing
|
||||||
|
for page in self._decorated_pages:
|
||||||
|
reflex.app.DECORATED_PAGES.remove(page)
|
||||||
|
|
||||||
def __exit__(self, *excinfo) -> None:
|
def __exit__(self, *excinfo) -> None:
|
||||||
"""Contextmanager protocol for `stop()`.
|
"""Contextmanager protocol for `stop()`.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user