[Numpy-discussion] ANN: NumPy 1.2.0

Anne Archibald peridot.faceted at gmail.com
Mon Sep 29 16:36:36 EDT 2008


2008/9/29 Francesc Alted <faltet at pytables.org>:

> But I agree with Robert Kern that tests *should* never be run under -OO
> because they are *tests*, not production code, and using the -OO for
> running the test units is simply a wrong practice.

I have to disagree with this. What if some piece of code misbehaves
when optimization is turned on? This frequently happens with C code,
and I would not be too surprised if it occurred with python code. The
easiest way, which I think is what Chuck was referring to as "abuse of
asserts" is for someone to write something like

try:
    while True:
        do_something()
        assert np.all(a<17)
except AssertionError:
    pass

This is of course a bug, though it may work, more or less, in
non-optimized code. But if you can't run your test suite in optimized
mode, it's going to be useless finding this bug.

Perhaps more plausibly, someone might use assert to check the validity
of user input. Then you turn on optimization and use input becomes
unchecked...

I support getting rid of assert statements in tests. How hard is it to
create a function assert_ in numpy.Testing?

assert np.all(a<17), "oops"

becomes

assert_(np.all(a<17), "oops")

It could even be done automatically, or nearly.



Anne



More information about the NumPy-Discussion mailing list