单元测试:断言存在文件/路径

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

我正在尝试为我的安装程序创建回归测试。回归测试是用Python编写的脚本。测试检查是否在正确的位置安装了正确的文件。

有没有办法断言文件/文件夹存在?我收到以下代码的AssertionError错误:

assert os.path.exists(LOCAL_INSTALL_DIR) == 1

为什么我会收到此错误,如何解决?我的功能:

def check_installation_files_exist():
    assert os.path.exists(LOCAL_INSTALL_DIR) == 1
    assert os.path.exists(INSTALL_DIR) == 1
    correct_install_files = normalise_file_names( os.listdir( LOCAL_INSTALL_DIR ) )
    installed_files       = normalise_file_names( os.listdir( INSTALL_DIR ) )
python unit-testing assert
1个回答
7
投票

LOCAL_INSTALL_DIR描述的路径要么不存在,要么是一个破碎的符号链接,或者你没有获得stat()的许可。

© www.soinside.com 2019 - 2024. All rights reserved.