[Zope-Coders] Help with Unit Testing: safe imports

Jeremy Hylton jeremy@alum.mit.edu
Mon, 19 Aug 2002 10:41:31 -0400


>>>>> "TS" == Tres Seaver <tseaver@zope.com> writes:

  TS> Python's own 'unittest.py' fails silently if the test module
  TS> bails with import errors.

I can't figure out what you mean.  If I write a unittest module, I
import unittest and I may even call its main.  But if an import fails
before I invoke unittest, we can hardly say that unittest fails.  It
hasn't even been invoked.

If an ImportError occurs during a test run, unittest will catch that
and mark the test as failed.

  TS> Successful import of the module-under-test should *not* be
  TS> assumed by the test module..

No, but it shouldn't be coded around either.  The test module should
fail with an ImportError if the module-under-test can't be imported.

Jeremy