unittest: How to fail if environment does not allow execution?

Roy Smith roy at panix.com
Wed May 10 13:57:19 EDT 2006


Kai Grossjohann  <kai.grossjohann at verizonbusiness.com> wrote:
> I wrote a test case that depends on a certain file existing in the
> environment.

In theory, unit tests should not depend on any external factors, but
we all know the difference between theory and practice, right?

> So, I guess I should test that the file exists in the
> setUp method.  But what if it doesn't exist?  How do I fail in that case?

def setUp (self):
    try:
        open ("myEssentialTestFile")
    except IOError:
        self.fail ("Hey, dummy, myEssentialTestFile is missing!")



More information about the Python-list mailing list