在python单元测试中模拟打开文件?

问题描述 投票:0回答:1

我正在尝试对下面给出的功能进行单元测试:

def _get_file(file_name):
    """
    Retrieves file.
    :param file_name: file
    :return:
    """
    try:
        with open(os.path.join(DIR, file_name), 'r') as file:
            contents = file.read()
    except Exception as FileNotFoundError:
        logging.error(FileNotFoundError)
    else:
        file.close()
        return query

我想测试此功能,但似乎无法绕开它。任何想法我该怎么做

python-2.7
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.