devtools/__init__.py
branchstable
changeset 9564 e2d5b0712974
parent 9337 70f6b183085a
child 9600 bde625698f44
--- a/devtools/__init__.py	Wed Mar 05 15:49:23 2014 +0100
+++ b/devtools/__init__.py	Mon Mar 10 16:07:41 2014 +0100
@@ -108,6 +108,7 @@
         repo._needs_refresh = True
         repo._has_started = False
 
+
 def turn_repo_on(repo):
     """Idea: this is less costly than a full re-creation of the repo object.
     on:
@@ -820,7 +821,22 @@
 
 
 # XXX a class method on Test ?
+
+_CONFIG = None
 def get_test_db_handler(config):
+    global _CONFIG
+    if _CONFIG is not None and config is not _CONFIG:
+        from logilab.common.modutils import cleanup_sys_modules
+        # cleanup all dynamically loaded modules and everything in the instance
+        # directory
+        apphome = _CONFIG.apphome
+        if apphome: # may be unset in tests
+            cleanup_sys_modules([apphome])
+        # also cleanup sys.path
+        if apphome in sys.path:
+            sys.path.remove(apphome)
+    _CONFIG = config
+    config.adjust_sys_path()
     handler = HCACHE.get(config)
     if handler is not None:
         return handler