[BUG][MERGE] 'bzr upgrade' broken by lazy imports

John Arbash Meinel john at arbash-meinel.com
Tue Nov 7 19:42:09 GMT 2006


Aaron Bentley wrote:
> John Arbash Meinel wrote:

...

> 
> This looks okay, but is there any way we can test it?
> 
> Aaron

Our test suite is incapable (ATM) of testing import order issues,
especially like this one.

Because when the test suite is loaded, we load all of the tests to find
out what we need to run, and then run the selected tests.

One thing we *could* do, is change 'run_bzr()' so that it actually
spawned a sub-process. But the whole reason we avoided that was because
it is very very slow.

Also, I think some of our tests involve changing a parameter in bzrlib,
and then calling run_bzr() to make sure it does what we expect.

I would hope that there aren't many of those. But yes, finding a way to
test for import order is something we still need to do. We discussed it
a little in Sydney, and we can write tests that assert each file can be
imported by itself (so we don't have weird recursive import issues), but
you actually have to run the code to find out that:

import bzrlib

def func(bar):
  bzrlib.foo.bar(bar)

Is failing because 'bzrlib.foo' is never being imported. Just importing
this code will succeed. (And if another place imported bzrlib.foo, it
would work too. Which is our current source of bugs).

So for now, I'm just trying to do a code audit. As it is something that
can be determined visually pretty easily. I suppose we could write a
text scanner that would look for 'bzrlib.foo' being accessed without a
corresponding 'import bzrlib.foo' style line.

Though that fails for 'bzrlib.user_encoding', since that is a direct
variable. Though I would like to see us use
bzrlib.osutils.get_user_encoding() instead, since it would let us delay
loading the locale module until we have to.

Martin mentioned that he though pyflakes should be able to catch things
like this, but pyflakes doesn't (yet?) understand the new lazy_import()
directives, which will mean ATM it will catch far too many false positives.

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20061107/04402e82/attachment.pgp 


More information about the bazaar mailing list