我有以下测试模块,在FreeBSD上的Python2.7中运行:
from mock import patch
from t.conf import load_config
@patch('t.conf._load_file')
def test_open_file(mock_open):
string_read = load_config('foo')
print(repr(string_read))
如果我注释掉patch
行,它运行良好。如果我把它留在里面,它会在挂了10分钟后把我的机器撞坏。我在其他地方使用patch
,没有任何问题。发生什么事?你知道吗
_load_file
看起来像这样:
def _load_file(filename):
with open(filename, 'rb') as f:
return f.read()
而load_config
看起来是这样的:
def load_config(filename):
text = _load_file(filename)
data = yaml.safe_load(text)
return data
目前没有回答
相关问题 更多 >
编程相关推荐