我正在使用其他人的测试代码,他们大量使用mocker。问题是我更改了底层代码,所以它使用Path().is_file测试文件是否存在。
现在我需要模拟Path().is_file,使其返回True。我试过了:
from pathlib import Path @pytest.fixture(scope="function") def mock_is_file (mocker): # mock the AlignDir existence validation mocker.patch ('Path.is_file') return True
我收到此错误:
E ModuleNotFoundError: No module named 'Path' /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/unittest/mock.py:1161: ModuleNotFoundError
修补Path.is_file()的正确方法是什么?