[omniORB] Weird interaction between omniORBpy 2.0 and PyUnit 1.4.1

Duncan Grisby duncan@grisby.org
Wed Mar 26 18:29:02 2003


On Wednesday 26 March, cp@sophos.com wrote:

> I have encountered an annoying problem when using omniORBpy 2.0 and PyUnit 
> 1.4.1 with Python 2.2. If I use the unittestgui to execute the tests I can 
> only run the test once. The first run of my test suite goes ok, but the 
> second run displays the following error:

[...]
> AttributeError: 'module' object has no attribute 'SimpleTestSuite'

The error is due to this bit of dodgy code in unittestgui.py:

class RollbackImporter:
    """This tricky little class is used to make sure that modules under test
    will be reloaded the next time they are imported.
    """
    def __init__(self):
        self.previousModules = sys.modules.copy()
        
    def rollbackImports(self):
        for modname in sys.modules.keys():
            if not self.previousModules.has_key(modname):
                # Force reload when modname next imported
                del(sys.modules[modname])


The problem arises because the omniORB extension module, called
_omnipy, installs several extra sub-modules. Extension modules are
only initialised once, no matter whether they have vanished from
sys.modules or not. This means that although the top _omnipy module
comes back, its submodules do not. This leads to an ImportError, which
is swallowed by code in unittest.py, and eventually turns into the
strange error you get.

I'd say this is a limitation of unittestgui, rather than a bug in
either it or omniORBpy.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan@grisby.org     --
   -- http://www.grisby.org --