mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +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:
parent
bf5d010ba1
commit
e9802185b4
19
django/test/rollback_importer.py
Normal file
19
django/test/rollback_importer.py
Normal 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
|
Loading…
x
Reference in New Issue
Block a user