在使用pytest导入期间,如何正确模拟出一个类? 例如:
#main_module.py
from james import John
class Fish:
def run():
return John()
#test_main_module.py
@patch('path/to/main_module/where/John/was/used')
def test_main_module_uses_mork(mocker):
MockJohn = mocker.Mock()
assert type(Fish().run()) == MockJohn