Using CleanImport to revert a reload of the os module doesn't work due to function registrations in copy_reg. The perils of reloading modules even for tests...

This commit is contained in:
Nick Coghlan 2009-10-18 05:38:48 +00:00
parent 83f1ef681f
commit 9039b83c53
2 changed files with 24 additions and 5 deletions

View file

@ -43,7 +43,14 @@ class ReloadTests(unittest.TestCase):
reload()."""
def test_source(self):
with test_support.CleanImport('os'):
# XXX (ncoghlan): It would be nice to use test_support.CleanImport
# here, but that breaks because the os module registers some
# handlers in copy_reg on import. Since CleanImport doesn't
# revert that registration, the module is left in a broken
# state after reversion. Reinitialising the module contents
# and just reverting os.environ to its previous state is an OK
# workaround
with test_support.EnvironmentVarGuard():
import os
imp.reload(os)