# HG changeset patch # User Sylvain Thénault # Date 1394464061 -3600 # Node ID e2d5b07129742c64f37415623a46e93dba35c5b5 # Parent 97fed7743dbef971b7a5d97184c3193f378822c6 [test] when the config change, we should cleanup sys.path and sys.modules. Closes #3634164 Without this, modules imported within instance home will be messed up. diff -r 97fed7743dbe -r e2d5b0712974 devtools/__init__.py --- 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