[Tutor] Testing dymamically created methods

Thomas Maier hayzer at gmail.com
Tue Jan 10 15:37:20 CET 2012


On Tue, Jan 10, 2012 at 3:31 PM, Walter Prins <wprins at gmail.com> wrote:
> 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
Works perfect.

> 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
Will try later.

> HTH, my $0.02 worth,
>
> Walter

Thank you very much!

Thomas


More information about the Tutor mailing list