Skip to content

Instantly share code, notes, and snippets.

@Bas-Man
Created December 13, 2018 14:18
Show Gist options
  • Save Bas-Man/5869412f93469f4654e6618091ddbc83 to your computer and use it in GitHub Desktop.
Save Bas-Man/5869412f93469f4654e6618091ddbc83 to your computer and use it in GitHub Desktop.
How to catch an OSError for invalid directory path or file in UnitTest in Python 3.x
def testValidatePathFile(self):
with self.assertRaises(OSError) as cm:
# self.handle.__ValidatePathFile()
self.handle = exceptman.ExceptionListManager(path="/tm")
err = cm.exception
self.assertEqual(str(err), "[Errno 2] No such file or directory: '/tm'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment