如果 Pytest 中不存在文件,如何断言?
How to assert if file does not exist in 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
我知道如何断言文件是否存在,但不确定如果文件不存在最好的方法是什么。我正在使用 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