Try recursive patching

This commit is contained in:
Leon Luithlen 2024-11-12 13:53:48 +01:00
parent 501d2107a9
commit 636bfae7a2

View file

@ -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