diff --git a/reflex/config.py b/reflex/config.py index ef48895ea..9a86e0f26 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -825,6 +825,17 @@ def get_config(reload: bool = False) -> Config: return Config(app_name="") rxconfig = importlib.import_module(constants.Config.MODULE) return rxconfig.config + except Exception: + sys.path.extend(sys_path) + # only import the module if it exists. If a module spec exists then + # the module exists. + spec = find_spec(constants.Config.MODULE) + if not spec: + # we need this condition to ensure that a ModuleNotFound error is not thrown when + # running unit/integration tests or during `reflex init`. + return Config(app_name="") + rxconfig = importlib.import_module(constants.Config.MODULE) + return rxconfig.config finally: sys.path.clear() sys.path.extend(sys_path)