|-- my_module
| |-- __init__.py
| |-- function.py
`-- test.py
在function.py
:补丁功能
import other_function
def function():
doStuff()
other_function()
return
在__init__.py
from .function import function
在我test.py
from django.test import TestCase
from mock import patch
from my_module import function
class Test(TestCase):
@patch('my_module.function.other_function')
def function_test(self, mock_other_function):
function()
当我运行这个时,我得到了一个 Attri buteError:
<@task: my_module.function.function of project:0x7fed6b4fc198> does not have the attribute 'other_function'
这意味着我试图修补功能“功能”,而不是模块“功能”。我不知道如何让它理解我想修补模块。
我也想避免重命名我的模块或功能。
任何想法?
[编辑] 你可以在https://github.com/vthorey/example_mock 运行找到一个例子
python manage.py test
你有解决这个问题吗? –
@HaykDavtyan没有。如果您想提高知名度,您可以提出问题;) –