|-- 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沒有。如果您想提高知名度,您可以提出問題;) –