Thanks for the code.
I am doing similar thing, only thing is setup is called twice which is not a 
problem though.

rgds
Anurag

----- Original Message ----
From: holger krekel <[EMAIL PROTECTED]>
To: anurag uniyal <[EMAIL PROTECTED]>
Cc: py-dev@codespeak.net
Sent: Tuesday, July 3, 2007 4:39:36 PM
Subject: Re: [py-dev] generative tests : setup/teardown?


Hi Anurag! 

On Tue, Jul 03, 2007 at 03:53 -0700, anurag uniyal wrote:
> Hi,
> 
> I have just changed our testing framework from PyUnit to py.tests and so I am 
> very new to it.
> 
> I was trying to write some generative tests so that my mutiple tests can be 
> easily generated as they differ only by few parameters.
> It works fine except that it seem generative tests are not treated equal to 
> normal tests (test_*)
> because setup_method is not called every time for each generated tests and 
> that makes it impossible for me to use generative tests in my case.
> 
> Is it expected behaviour? what is the alternative?

it's known and expected behaviour.  The setup/teardown mechanics apply 
to the generator which yields/generates the actual test functions/params. 

However, you might call setup/teardown methods directly from
the generated tests.  Find below a code example which you can
run with "py.test test_gensetup.py" if you write it to a file. 

hope it helps. 

best, 

holger

---- test_gensetup.py ---- 


def mysetup(para):
    print "mysetup gentest", para

def myteardown(para):
    print "myteardown gentest", para

def gentest(para):
    assert 4 == para

def gentestwrapper(para):
    mysetup(para)  # could also call existing setup_function()/setup_method()
    try:
        gentest(para)
    finally:
        myteardown(para)

def test_generated():
    for x in 1,2,3:
        yield gentestwrapper, x


       
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell. 
http://searchmarketing.yahoo.com/
_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev

Reply via email to