lundi 28 mai 2018

Python test for missing static file

I have the following MWE (the actual code is bigger, but this is the part I want to test):

def processFile():
  try:
    with open("localFile.txt", "rb") as f:
      # Process file here
  except EnvironmentError:
    # Handle Exception

My question is: How can I test the function above, to test whether the exception is thrown or not. My understanding of testing (which is very limited) is, that one is calling the function in a test and causing the "failure" to happen, while asserting.

But how can I invalidate the presence of the file, without actually deleting it? Thanks!

Aucun commentaire:

Enregistrer un commentaire