[Tutor] Testing dymamically created methods

Walter Prins wprins at gmail.com
Tue Jan 10 14:31:23 CET 2012


On 10 January 2012 12:15, Thomas Maier <hayzer at gmail.com> wrote:
> This code works without py.test or nosetests. For example if I use print
> instead of 'assert'.
> Both py.test and nosetests failed to execute this correctly.
> Or maybe they do execute it correctly, I just don't understand it..:)
> They both report only single test was executed.
> I would like to see test report for each method executed in 'for' loop.
> Is it possible?

For nose, I *think* you can basically achieve what you want by turning
test_run() into a generator (by essentially replacing the call to the
test_method() with a suitable "yield" statement.   See here:

Additionally you might also look at the TestLoader functionality for
taking further control over how and where your tests are loaded, e.g.
see for example nose.loader.loadTestsFromGenerator() or
nose.loader.loadTestsFromGeneratorMethod() (or indeed all the other
methods) here:

HTH, my $0.02 worth,


More information about the Tutor mailing list