# HG changeset patch # User fschwarz # Date 1300569214 0 # Node ID 59db0f962e000e8fa07f3a1530c317782f92e823 # Parent bf8b876cb8c78c8b8ab2e8f013a3bc3b68e73b03 test refactoring: clear global babel logger handlers to decrease test interdependencies (follow-up on #227) diff --git a/babel/messages/tests/frontend.py b/babel/messages/tests/frontend.py --- a/babel/messages/tests/frontend.py +++ b/babel/messages/tests/frontend.py @@ -513,13 +513,7 @@ sys.stderr = StringIO() os.chdir(self.datadir) - # Logging handlers will be reused if possible (#227). This breaks the - # implicit assumption that our newly created StringIO for sys.stderr - # contains the console output. Removing the old handler ensures that a - # new handler with our new StringIO instance will be used. - log = logging.getLogger('babel') - for handler in log.handlers: - log.removeHandler(handler) + self._remove_log_handlers() self.cli = frontend.CommandLineInterface() def tearDown(self): @@ -531,6 +525,16 @@ locale_dir = os.path.join(self.datadir, 'project', 'i18n', dirname) if os.path.isdir(locale_dir): shutil.rmtree(locale_dir) + self._remove_log_handlers() + + def _remove_log_handlers(self): + # Logging handlers will be reused if possible (#227). This breaks the + # implicit assumption that our newly created StringIO for sys.stderr + # contains the console output. Removing the old handler ensures that a + # new handler with our new StringIO instance will be used. + log = logging.getLogger('babel') + for handler in log.handlers: + log.removeHandler(handler) def test_usage(self): try: