1
0
mirror of https://github.com/django/django.git synced 2025-07-05 10:19:20 +00:00

[gsoc2009-testing] Adding my global importer which can force a reload of all modules. (so coverage can account for startup as well)

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/test-improvements@11296 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Kevin Kubasik 2009-07-22 13:17:49 +00:00
parent bf5d010ba1
commit e9802185b4

View File

@ -0,0 +1,19 @@
class RollbackImporter:
def __init__(self):
"Creates an instance and installs as the global importer"
self.previousModules = sys.modules.copy()
self.realImport = __builtin__.__import__
__builtin__.__import__ = self._import
self.newModules = {}
def _import(self, name, globals=None, locals=None, fromlist=[]):
result = apply(self.realImport, (name, globals, locals, fromlist))
self.newModules[name] = 1
return result
def uninstall(self):
for modname in self.newModules.keys():
if not self.previousModules.has_key(modname):
# Force reload when modname next imported
del(sys.modules[modname])
__builtin__.__import__ = self.realImport