[Python-Dev] More joy with test_strptime

Tim Peters tim.peters at gmail.com
Tue Jul 13 07:33:18 CEST 2004


[Brett]
> OK, so the question becomes how can I have test_site (which I will fix
> with your suggestions for the removal of existing files and directories;
> when I rewrote that chunk of code I had EAFP on the brain) test to make
> sure that a module is imported?

By making sure the module it imports isn't in sys.modules before it
tries to import it.  Beforehand:

    old_version = sys.modules.get(self.imported)
    if old_version is not None:
        del sys.modules[self.imported]

Then make sure the .pth file puts self.imported back in sys.modules.

At the end,

    del sys.modules[self.imported]
    if old_version is not None:
        sys.modules[self.imported] = old_version


More information about the Python-Dev mailing list