ENH+BF: Reintroduce the config manager and add switches

bugfix: restore the environment even when a test fails.