[Tutor] Testing dymamically created methods
Walter Prins
wprins at gmail.com
Tue Jan 10 14:31:23 CET 2012
Hi,
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:
http://readthedocs.org/docs/nose/en/latest/writing_tests.html#test-generators
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:
http://readthedocs.org/docs/nose/en/latest/api/loader.html
HTH, my $0.02 worth,
Walter
More information about the Tutor
mailing list