How to assert if file does not exist in Pytest?

Viewed 2190

I know how to assert if a file does exist, but not sure what the best way to do it is if it doesn't exist. I'm using pytest.

I have this so far, but this asserts if file does exist. I thought maybe using ! or not but not sure what the standard way to do it is. Bit of a noob. Thanks!

    path = os.path.join("cs.log")
    assert not path.is_file()   
1 Answers
if not os.path.exists("cs.log"):
    #stuff
    pass

Or, using assert:

assert os.path.exists("cs.log") == False
Related