Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单元测试:断言文件/路径存在_Python_Unit Testing_Assert - Fatal编程技术网

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

Python 单元测试:断言文件/路径存在,python,unit-testing,assert,Python,Unit Testing,Assert,我正在尝试为我的安装程序创建回归测试。回归测试是用Python编写的脚本。测试将检查是否在正确的位置安装了正确的文件 有没有办法断言文件/文件夹存在?我收到以下代码的AssertionError错误: assert os.path.exists(LOCAL_INSTALL_DIR) == 1 为什么我会出现这个错误?我如何修复它?我的职能: def check_installation_files_exist(): assert os.path.exists(LOCAL_INSTALL

我正在尝试为我的安装程序创建回归测试。回归测试是用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 ) )

LOCAL\u INSTALL\u DIR
所描述的路径不存在,是一个断开的符号链接,或者您没有权限
stat()
它。

您收到错误,因为该路径不存在,按计划,另外,没有必要使用
==1
@downvoter为什么downvotei没有进行downvote,但我猜这是因为您的案例太本地化了,这不保证进行downvoter,只有结束vote@jamylak试图断言文件存在是非常本地化的,实际上lol,踏入未知领域,我应该在历史书上aye@jamylak我在编写一个单元测试来检查删除文件是否正常工作时发现了这个讨论。在web应用程序中,可能还有许多其他应用程序中,文件的正确删除通常是相关的。我想知道为什么写一个关于它的测试是如此本地化和特殊的事情。