[SciPy-Dev] Generator tests

Pauli Virtanen pav at iki.fi
Fri Jul 13 05:57:01 EDT 2012


Ralf Gommers <ralf.gommers <at> googlemail.com> writes:
[clip]
> in the test or code. Plus, it once again shows how
> annoying generator tests are; can't see which method is
> failing. 

Here's a recommendation for generator test:

- No computation related to the features tested should be
  done in the test_* generator function, but delegated to
  a corresponding _check_* function (can be inside the
  generator, to share namespace).

- The generators should be used *solely* for loops over parameters.

- These parameters should *not* be arrays.

  If a parameter is "complicated", as in the case of ARPACK
  tests, wrap it into a class with a descriptive __repr__ method.

Like so:

def test_foo():
    x = [1, 2, 3]
    z = 9

    def check(a, b):
        x = a + b + z
        y = a - b + z
        assert x == y + 2*b

    for a in [1, 2, 3]:
        for b in [4, 5, 6]:
            yield check, a, b

-- 
Pauli Virtanen




More information about the SciPy-Dev mailing list