From e56a0b3d29e6e0a6a124b7551639b4b440eda032 Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 19 Jul 2025 21:56:08 +0800 Subject: [PATCH] fix: resolve Redis mock import error in test configuration - Add API directory to Python path before importing extensions - Replace string-based patch with patch.object for more reliable mocking - Fix "AttributeError: module 'extensions' has no attribute 'ext_redis'" error This ensures the test environment correctly imports and mocks the Redis client, preventing module resolution issues when running tests. --- api/tests/unit_tests/conftest.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/tests/unit_tests/conftest.py b/api/tests/unit_tests/conftest.py index 077ffe3408..f484fb22d3 100644 --- a/api/tests/unit_tests/conftest.py +++ b/api/tests/unit_tests/conftest.py @@ -26,8 +26,15 @@ redis_mock.hgetall = MagicMock(return_value={}) redis_mock.hdel = MagicMock() redis_mock.incr = MagicMock(return_value=1) +# Add the API directory to Python path to ensure proper imports +import sys + +sys.path.insert(0, PROJECT_DIR) + # apply the mock to the Redis client in the Flask app -redis_patcher = patch("extensions.ext_redis.redis_client", redis_mock) +from extensions import ext_redis + +redis_patcher = patch.object(ext_redis, "redis_client", redis_mock) redis_patcher.start()