From 1d56f8570502ef7a7de359bceb36649cacfa984c Mon Sep 17 00:00:00 2001 From: UmranPros <152087084+umran666@users.noreply.github.com> Date: Fri, 12 Jun 2026 19:40:26 +0530 Subject: [PATCH] fix(cli): resolve Windows environment compatibility issues in python CLI tests (#5464) Co-authored-by: Kartik --- cli/python/tests/test_agent_mode.py | 9 ++++++--- cli/python/tests/test_cli_integration.py | 3 ++- cli/python/tests/test_config.py | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cli/python/tests/test_agent_mode.py b/cli/python/tests/test_agent_mode.py index 78f0ca48c..d7b609e15 100644 --- a/cli/python/tests/test_agent_mode.py +++ b/cli/python/tests/test_agent_mode.py @@ -32,12 +32,13 @@ def _run(args: list[str], home_dir: str | None = None) -> subprocess.CompletedPr if key.startswith("MEM0_"): del env[key] env.pop("FORCE_COLOR", None) + env["PYTHONIOENCODING"] = "utf-8" if home_dir: env["HOME"] = home_dir result = subprocess.run( [sys.executable, "-m", "mem0_cli", *args], capture_output=True, - text=True, + encoding="utf-8", env=env, timeout=15, ) @@ -99,12 +100,13 @@ class TestArgvPreprocessing: result = subprocess.run( [sys.executable, "-m", "mem0_cli", "init", "--agent"], capture_output=True, - text=True, + encoding="utf-8", env={ **{k: v for k, v in os.environ.items() if not k.startswith("MEM0_")}, "HOME": clean_home, "MEM0_BASE_URL": "http://127.0.0.1:1", # blackhole "FORCE_COLOR": "0", + "PYTHONIOENCODING": "utf-8", }, timeout=15, ) @@ -133,12 +135,13 @@ class TestJsonEnvelopeParity: result = subprocess.run( [sys.executable, "-m", "mem0_cli", "init", "--agent", "--json"], capture_output=True, - text=True, + encoding="utf-8", env={ **{k: v for k, v in os.environ.items() if not k.startswith("MEM0_")}, "HOME": clean_home, "MEM0_BASE_URL": "http://127.0.0.1:1", "FORCE_COLOR": "0", + "PYTHONIOENCODING": "utf-8", }, timeout=15, ) diff --git a/cli/python/tests/test_cli_integration.py b/cli/python/tests/test_cli_integration.py index ea6607201..8abd145d0 100644 --- a/cli/python/tests/test_cli_integration.py +++ b/cli/python/tests/test_cli_integration.py @@ -49,6 +49,7 @@ def _run( if key.startswith("MEM0_"): del env[key] env.pop("FORCE_COLOR", None) + env["PYTHONIOENCODING"] = "utf-8" if home_dir: env["HOME"] = home_dir if env_override: @@ -56,7 +57,7 @@ def _run( result = subprocess.run( [sys.executable, "-m", "mem0_cli", *args], capture_output=True, - text=True, + encoding="utf-8", env=env, ) return subprocess.CompletedProcess( diff --git a/cli/python/tests/test_config.py b/cli/python/tests/test_config.py index 48db01481..86dc2561b 100644 --- a/cli/python/tests/test_config.py +++ b/cli/python/tests/test_config.py @@ -67,7 +67,8 @@ class TestConfig: from mem0_cli.config import CONFIG_FILE mode = os.stat(CONFIG_FILE).st_mode & 0o777 - assert mode == 0o600 + if os.name != "nt": + assert mode == 0o600 def test_defaults_save_and_load(self, isolate_config): config = Mem0Config()