[TIP] py.test best way to generate a *lot* of tests

holger krekel holger at merlinux.eu
Wed Jun 13 07:38:57 PDT 2012


Hey Thijs,

not sure i exactly understand your problem yet ...

On Wed, Jun 13, 2012 at 15:22 +0200, Thijs Engels wrote:
> I am currently experimenting with py.test to validate result which are
> written to a database. Hence more functional testing than unittesting.
> The database interface is completely dealt with via SQLAlchemy, hence
> the tests merely have to iterate over all the objects.
> 
> The issue I am currently running into is the fact that the output
> consists of sessions, which in itself contains specific data for this
> session. The amount of data (objects) is however different per session.
>
> Which if I understand correctly need to be extracted to create a full
> list (of objects) for the parametrization. This seems fine if were just
> these sessions and their child, but there are more levels, and worse
> there are thousands of objects.

Could you try to show some example (basic/pseudo) code of what you want to
achieve?
 
> I do realize I might be using this test framework for something it was
> not really meant for, but is it indeed only possible to have py.test go
> through all these objects if the first step is creating (huge) lists
> with the actual objects to be fed into the parametrize function?

Did you look into the pytest_generate_tests hook where you can write
code (interacting with a database, for example) which then triggers
parametrization?  Here is a basic example:

    http://pytest.org/latest/example/parametrize.html#generating-parameters-combinations-depending-on-command-line
    
FWIW, i consider it within pytest's mission to support database-driven
parametrized testing so if there are issues i'd like to help work them out.

best,
holger



More information about the testing-in-python mailing list