5

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()   
caasswa
  • 501
  • 3
  • 10

1 Answers1

13
if not os.path.exists("cs.log"):
    #stuff
    pass

Or, using assert:

assert os.path.exists("cs.log") == False
Synthase
  • 5,849
  • 2
  • 12
  • 34