This tricky little class is used to make sure that modules under test will be reloaded the next time they are imported.
| 186 | |
| 187 | |
| 188 | class RollbackImporter: |
| 189 | """This tricky little class is used to make sure that modules under test |
| 190 | will be reloaded the next time they are imported. |
| 191 | """ |
| 192 | def __init__(self): |
| 193 | self.previousModules = sys.modules.copy() |
| 194 | |
| 195 | def rollbackImports(self): |
| 196 | for modname in sys.modules.copy().keys(): |
| 197 | if not modname in self.previousModules: |
| 198 | # Force reload when modname next imported |
| 199 | del(sys.modules[modname]) |
| 200 | |
| 201 | |
| 202 | ############################################################################## |