From 636bfae7a2390552839f89a50e416a791cb8bd88 Mon Sep 17 00:00:00 2001 From: Leon Luithlen Date: Tue, 12 Nov 2024 13:53:48 +0100 Subject: [PATCH] Try recursive patching --- cognee/tests/unit/run_tasks/conftest.py | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cognee/tests/unit/run_tasks/conftest.py b/cognee/tests/unit/run_tasks/conftest.py index 2e3523e36..2cb56e933 100644 --- a/cognee/tests/unit/run_tasks/conftest.py +++ b/cognee/tests/unit/run_tasks/conftest.py @@ -1,10 +1,19 @@ -from unittest.mock import patch +import sys import warnings +from unittest.mock import patch + import pytest from cognee.modules.users.methods.get_default_user import get_default_user from cognee.tests.unit.utils.get_mock_user import get_mock_user -import sys + + +def apply_with_to_item(module_items, fn, fn_str): + for i, (name, module) in enumerate(module_items): + if hasattr(module, fn_str) and not "test" in name: + with patch(name, fn): + if len(module_items[(i + 1) :]) > 0: + apply_with_to_item(module_items[(i + 1) :], fn, fn_str) @pytest.fixture(autouse=True, scope="session") @@ -12,16 +21,8 @@ def set_get_mock_user_wrapper(): def get_mock_user_wrapper(): return get_mock_user(None, None) - - for name, module in sys.modules.items(): - if hasattr(module, 'get_default_user'): - warnings.warn(f"Found get_default_user in module: {name}") - - with patch( - "cognee.modules.users.methods.get_default_user", get_mock_user_wrapper() - ): - with patch( - "cognee.modules.users.methods", get_mock_user_wrapper() - ): - with patch('cognee.modules.pipelines.operations.run_tasks', get_mock_user_wrapper()): - yield + + module_items = list(sys.modules.items()) + apply_with_to_item(module_items, get_mock_user_wrapper(), "get_default_user") + + yield