python - 如果文件在 Pytest 中不存在,如何断言?
问题描述
我知道如何断言文件是否存在,但不确定如果文件不存在最好的方法是什么。我正在使用pytest。
到目前为止我有这个,但这会断言文件是否存在。我想也许使用!
或not
但不确定标准的方法是什么。有点菜鸟。谢谢!
path = os.path.join("cs.log")
assert not path.is_file()
解决方案
if not os.path.exists("cs.log"):
#stuff
pass
或者,使用assert
:
assert os.path.exists("cs.log") == False
推荐阅读
- python - 如何从 Python 中的文件中删除“\n”行?
- node.js - 为什么我在发布请求时收到速率限制错误?
- python - sklearn.model_selection.KFold 和 sklearn.model_selection.cross_validate 与 'cv' 参数的区别?
- python - 如何在我的 Django 应用程序中集成排名算法
- c# - 如何规范化从 Kinect C# 中提取的特征?
- c# - 托管 .NET Core 运行时中的托管代码会损坏调用程序堆栈
- r - 如何在ggplot中按类别绘制答案?
- php - PHP:在数组之间添加缺少的键
- python - 我如何传送 (wormy.py)
- file - Jenkins管道与maven,指定的全局设置文件不存在