Try recursive patching
This commit is contained in:
parent
501d2107a9
commit
636bfae7a2
1 changed files with 16 additions and 15 deletions
|
|
@ -1,10 +1,19 @@
|
||||||
from unittest.mock import patch
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from cognee.modules.users.methods.get_default_user import get_default_user
|
from cognee.modules.users.methods.get_default_user import get_default_user
|
||||||
from cognee.tests.unit.utils.get_mock_user import get_mock_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")
|
@pytest.fixture(autouse=True, scope="session")
|
||||||
|
|
@ -12,16 +21,8 @@ def set_get_mock_user_wrapper():
|
||||||
|
|
||||||
def get_mock_user_wrapper():
|
def get_mock_user_wrapper():
|
||||||
return get_mock_user(None, None)
|
return get_mock_user(None, None)
|
||||||
|
|
||||||
for name, module in sys.modules.items():
|
module_items = list(sys.modules.items())
|
||||||
if hasattr(module, 'get_default_user'):
|
apply_with_to_item(module_items, get_mock_user_wrapper(), "get_default_user")
|
||||||
warnings.warn(f"Found get_default_user in module: {name}")
|
|
||||||
|
yield
|
||||||
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
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue