Python模拟运行pytest崩溃我的实例

2024-03-28 18:01:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下测试模块,在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

Tags: textfromimportconfigreadstringreturnconf