diff --git a/reflex/constants/__init__.py b/reflex/constants/__init__.py index e816da0f7..f5946bf5e 100644 --- a/reflex/constants/__init__.py +++ b/reflex/constants/__init__.py @@ -1,6 +1,7 @@ """The constants package.""" from .base import ( + APP_HARNESS_FLAG, COOKIES, IS_LINUX, IS_MACOS, diff --git a/reflex/constants/base.py b/reflex/constants/base.py index af96583ad..f737858c0 100644 --- a/reflex/constants/base.py +++ b/reflex/constants/base.py @@ -257,6 +257,7 @@ SESSION_STORAGE = "session_storage" # Testing variables. # Testing os env set by pytest when running a test case. PYTEST_CURRENT_TEST = "PYTEST_CURRENT_TEST" +APP_HARNESS_FLAG = "APP_HARNESS_FLAG" REFLEX_VAR_OPENING_TAG = "" REFLEX_VAR_CLOSING_TAG = "" diff --git a/reflex/testing.py b/reflex/testing.py index 582d7f8c9..65f81385e 100644 --- a/reflex/testing.py +++ b/reflex/testing.py @@ -283,6 +283,7 @@ class AppHarness: before_decorated_pages = reflex.app.DECORATED_PAGES[self.app_name].copy() # 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[reflex.constants.APP_HARNESS_FLAG] = "true" self.app_module = reflex.utils.prerequisites.get_compiled_app( # Do not reload the module for pre-existing apps (only apps generated from source) reload=self.app_source is not None diff --git a/reflex/utils/build.py b/reflex/utils/build.py index aeb8afd50..9ea941792 100644 --- a/reflex/utils/build.py +++ b/reflex/utils/build.py @@ -13,7 +13,7 @@ from rich.progress import MofNCompleteColumn, Progress, TimeElapsedColumn from reflex import constants from reflex.config import get_config from reflex.utils import console, path_ops, prerequisites, processes -from reflex.utils.exec import is_testing_env +from reflex.utils.exec import is_in_app_harness def set_env_json(): @@ -22,7 +22,7 @@ def set_env_json(): str(prerequisites.get_web_dir() / constants.Dirs.ENV_JSON), { **{endpoint.name: endpoint.get_url() for endpoint in constants.Endpoint}, - "TEST_MODE": is_testing_env(), + "TEST_MODE": is_in_app_harness(), }, ) diff --git a/reflex/utils/exec.py b/reflex/utils/exec.py index 621c4a608..1c777b854 100644 --- a/reflex/utils/exec.py +++ b/reflex/utils/exec.py @@ -487,6 +487,15 @@ def is_testing_env() -> bool: return constants.PYTEST_CURRENT_TEST in os.environ +def is_in_app_harness() -> bool: + """Whether the app is running in the app harness. + + Returns: + True if the app is running in the app harness. + """ + return constants.APP_HARNESS_FLAG in os.environ + + def is_prod_mode() -> bool: """Check if the app is running in production mode.