[BUG] python -O bzr selftest fails

John A Meinel john at arbash-meinel.com
Sat Oct 29 20:31:43 BST 2005


Aaron Bentley wrote:
> John A Meinel wrote:
>>> https://launchpad.net/products/bzr/+bug/3685
>>>
>>> In summary, because python -O turns off assert statements, not all
>>> commands are run in the test suite. There are several lines with "assert
>>> <something>" where <something> has a side effect.
> 
> This feels like one of those "Doctor, it hurts when I do this" "So stop
> doing that" situations.  Yes, we can turn assert into something else,
> but -O -O will still kill us hard, because we require docstrings to
> exist (e.g. in BzrNewError).
> 
> I'm inclined to do:
> assersions_work = False
> try:
>   assert False
> except:
>   assertions_work = True
> if not assertions_work:
>   raise BzrCommandError("Bzr selftest cannot be executed with -O")
> 
> It just seems dumb to me that we have built-in language support for
> assertions, but we can't use them where they're most convenient.
> 
> Aaron

I would say differently.
Because people might prefer to run with optimizations on, and they
should know that bzr still works properly in this mode.
(Simply edit 'bzr' to put #!/usr/bin/python2.4 -O bzr on some platforms)

It would be bad form for internal code to rely on assertions. Since an
assertion is supposed to say "this should never happen" not "if this
happens, bail out".
Running the test suite with optimizations active is important.

In the tests, we are currently using assert for the latter, when that is
what self.failUnless() is for.

I'm glad that you mentioned docstrings, though. I'm wondering if we
should fail to import bzrlib if someone does run bzr with -O -O. Because
both our help system, and our exceptions system will fail.

(I don't know how to detect it, though, other than checking to see if
known docstrings are missing).

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051029/0f439dbc/attachment.pgp 


More information about the bazaar mailing list