我有一个模块导入另一个模块,如下所示:
#main-file.py
import src.FetchFunction.video_service.fields.urls as urls
def some_func():
return urls.fetch()
现在我想像这样测试这个文件:
import unittest
import src.FetchFunction.video_service.fields.urls as urls
from unittest.mock import MagicMock
class MainFileTest(unittest.TestCase):
def test_example(self):
urls.fetch = MagicMock(return_value='mocked_resp')
assertSomething()
这部分运作良好,做我想要的。但这会影响其他测试文件...我的意思是我有其他测试使用“urls.fetch”,而现在他们获得了上面模拟的响应而不是获得正确的流程。
任何的想法?
pytest
来运行我的测试