单元测试:断言文件/路径存在 [英] Unit Testing: Assert that a file/path exists
本文介绍了单元测试:断言文件/路径存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为我的安装程序创建回归测试.回归测试是一个用 Python 编写的脚本.该测试检查是否已将正确的文件安装在正确的位置.
I am attempting to create a regression test for my Installer. The regression test is a script written in Python. The test checks that the correct files have been installed in the correct place.
有没有办法断言文件/文件夹存在?我收到以下代码的 AssertionError 错误:
Is there a way to assert that a file/folder exists? I am getting a AssertionError error for the following code:
assert os.path.exists(LOCAL_INSTALL_DIR) == 1
为什么我会收到这个错误,我该如何解决?我的功能:
Why am I getting this error and how can I fix it? My function:
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_INSTALL_DIR
描述的路径要么不存在,要么是损坏的符号链接,要么你没有的权限stat()
它.
The path described by LOCAL_INSTALL_DIR
either does not exist, is a broken symbolic link, or you do not have permission to stat()
it.
这篇关于单元测试:断言文件/路径存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文