[TIP] paramterized or generative tests [was nose2: the nosening]

Victoria G. Laidler laidler at stsci.edu
Thu Aug 5 19:54:25 PDT 2010

>       On Thu, Aug 5, 2010 at 9:31 PM, Michael
>       Foord<fuzzyman at voidspace.org.uk>  wrote:
>         On 06/08/2010 02:23, Jesse Noller wrote:
>           [snip...]
>           ps: If nose2/unittest2 could find it in it's shiny
>           new innocent heart
>           to say, have support for test generators; I'd die
>           happy.
>         Well there's another discussion :-)
>         It would be very simple to support parameterized tests
>         (of some form), where
>         the number of tests can be known at test load time.
>         Supporting generative
>         tests - where the tests are generated at *test run
>         time* is uglier.
>         Would parameterized tests, where the tests are all
>         generated at test load
>         time, suffice or do you have a use case for generative
>         tests where the tests
>         have to be generated whilst the tests are running and
>         not when the tests are
>         loaded?
>         Michael

Hi Michael & all,

I desperately need a clean way to run generated tests that a) get names I can control and b) attributes that can be defined and modified in the test itself that are then attached to the test case so I can access them via my report generator plugin.

I tried to do this with nose and it has really not worked out well - we are still using it in some places but just gave up and wrote a couple of simpler Pandokia-compliant test runners. I'd rather use a community standard so if we could get this into nose2 that would be great.

My immediate use case is as follows:

- I have a directory full of datafiles that define the inputs and expected outputs for the code under test

- The test itself should be python code that can:
   - import bits of test code (not just code under test) from elsewhere, including the code that does the following:
   - dynamically generate the tests based on the files that are present in the directory
   - name each test based on those filenames
   - invoke and execute the code under test
   - perform comparisons and save data about the comparisons in dictionaries attached to the test function


More information about the testing-in-python mailing list