我知道如何断言文件是否存在,但不确定如果文件不存在,最好的方法是什么。我正在使用 pytest。
到目前为止我已经有了这个,但这断言文件是否存在。我想也许可以使用!ornot但不确定执行此操作的标准方法是什么。有点菜鸟。谢谢!
path = os.path.join("cs.log")
assert not path.is_file()
Run Code Online (Sandbox Code Playgroud)
Syn*_*ase 13
if not os.path.exists("cs.log"):
#stuff
pass
Run Code Online (Sandbox Code Playgroud)
或者,使用assert:
assert os.path.exists("cs.log") == False
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8256 次 |
| 最近记录: |