[MERGE] Try harder to avoid loading plugins during the test suite.
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Dec 16 09:28:47 GMT 2008
I'm soo totally against even the spirit of this patch ! :-)
>>>>> "Andrew" == Andrew Bennetts <andrew.bennetts at canonical.com> writes:
Andrew> This is a bit of a band-aid. I think maybe a deeper fix would be better.
Andrew> But in the meantime, here's a patch that fixes a few parts of the test suite
Andrew> that would inadvertently load plugins while running the test suite. If you
Andrew> do “bzr --no-plugins selftest” it's rather surprising to get tracebacks with
Andrew> things like bzrlib/plugins/svn in them!
Andrew> -Andrew.
Andrew> # Bazaar merge directive format 2 (Bazaar 0.90)
Andrew> # revision_id: andrew.bennetts at canonical.com-20081216071405-\
Andrew> # s6bukfht1k4ts2eq
Andrew> # target_branch: http://bazaar-vcs.org/bzr/bzr.dev
Andrew> # testament_sha1: 1911628fee9c52a46cfb10a48a53ebd9828e1d3c
Andrew> # timestamp: 2008-12-16 18:14:09 +1100
Andrew> # source_branch: http://people.ubuntu.com/~andrew/bzr/no-plugins-\
Andrew> # testsuite
Andrew> # base_revision_id: pqm at pqm.ubuntu.com-20081216050844-csmbt4az61zghcxf
Andrew> #
Andrew> # Begin patch
Andrew> === modified file 'bzrlib/tests/__init__.py'
Andrew> --- bzrlib/tests/__init__.py 2008-12-11 03:08:03 +0000
Andrew> +++ bzrlib/tests/__init__.py 2008-12-16 07:14:05 +0000
Andrew> @@ -1409,6 +1409,7 @@
Andrew> stdout.encoding = encoding
Andrew> stderr.encoding = encoding
Andrew> + args = ['--no-plugins'] + args
Wow, when I saw that I thought: "That just makes it impossible to
use run_bzr to blackbox test plugins !"...
And happily went to test that hypothesis... and failed...
AFAIUI, --no-plugins is handled once for a given process by
calling bzrlib.plugin.disable_plugins() which calls
bzrlib.plugin.load_plugins([]) which in turn set a plugin._loaded
to True which ensures that we will never load plugins in that
process.
That's enough to explain why the above line has no effect for my
test... but since you added it I imagine it has an effect for
you...
Can you tell us *how* you produce tracebacks ?
Andrew> self.log('run bzr: %r', args)
Andrew> # FIXME: don't call into logging here
Andrew> handler = logging.StreamHandler(stderr)
Andrew> === modified file 'bzrlib/tests/test_plugins.py'
Andrew> --- bzrlib/tests/test_plugins.py 2008-11-15 19:41:37 +0000
Andrew> +++ bzrlib/tests/test_plugins.py 2008-12-16 07:14:05 +0000
Andrew> @@ -404,7 +404,9 @@
Andrew> def split_help_commands(self):
Andrew> help = {}
Andrew> current = None
Andrew> - for line in self.run_bzr('help commands')[0].splitlines():
Andrew> + out, err = self.run_bzr('--no-plugins help commands')
Andrew> + print err
Left out after debug ?
Andrew> + for line in out.splitlines():
Andrew> if not line.startswith(' '):
Andrew> current = line.split()[0]
Andrew> help[current] = help.get(current, '') + line
Andrew> @@ -635,9 +637,14 @@
Andrew> old_plugins_path = bzrlib.plugins.__path__
Andrew> bzrlib.plugins.__path__ = []
Andrew> plugin._loaded = False
Ha ! The culprit maybe ?
Andrew> + def load_from_path(dirs):
Andrew> + pass
Andrew> + old_load_from_path = plugin.load_from_path
Andrew> + plugin.load_from_path = load_from_path
Andrew> def restore_plugins():
Andrew> bzrlib.plugins.__path__ = old_plugins_path
Andrew> plugin._loaded = False
And again ! Argh.
Andrew> + plugin.load_from_path = old_load_from_path
Andrew> test_case.addCleanup(restore_plugins)
I can't go further without a recipe to reproduce the problem, but
I think a cleaner approach would be to not *load* test_plugins if
--no-plugins is passed on the command-line...
BB:comment
Vincent
P.S.: Jokes aside, I'm not sure people realize that running
selftest --no-plugins exclude even bzrlib.plugins.... which means
that bzr itself is not fully tested in that case (yeah, I realize
that's not the case on pqm, but yet...).
More information about the bazaar
mailing list