[py-dev] py.test : setup / teardown at the directory level

Philippe Fremy phil at freehackers.org
Thu Apr 30 10:22:54 CEST 2009


Hi Holger,

Thanks for looking into this.

I am quite busy until mid next week so it will take me a few days before
I get back to you.

cheers,

Philippe

holger krekel wrote:
> Hi Philippe, 
> 
> your described use case makes lots of sense to me. 
> 
> I coded an example which i hope fits it. 
> 
> It uses the new "local plugins" (i.e.  plugins defined in a
> conftest.py) and funcargs, if you don't know about them
> yet i hope this is good to skim/read first: 
> http://codespeak.net/py/trunk/test/funcargs.html
> 
> Here is the example: 
> 
>     http://bitbucket.org/hpk42/py-trunk/src/tip/example/funcarg/lazysetup/
> 
> using py-trunk (probably also works with the 1.0.0b1, haven't checked)
> in the lazysetup directory you can now do
> 
>     py.test sub1   # will wait 5 seconds because test
>                    # functions access the setup defined in
>                    # conftest.py 
> 
>     py.test sub2   # will immediately run as the "setup"
>                    # funcarg is not requested 
>                    
> The idea for this conftest.py implementation is simple: 
> setup the funcarg when first needed and only tear it down
> when the test process exits.  
> 
> does this make sense to you?  feel free to play around
> and ask questions - I'd then put the above example into 
> the "tutorial" example section of the funcarg doc. 
> 
> One advantage of the above approach is that you do not
> need to do anything in your test modules anymore 
> (no boilerplate importing of setup_module etc.) 
> than requesting the object you want to setup. 
> 
> cheers,
> holger
> 
> On Tue, Apr 28, 2009 at 17:09 +0200, Philippe Fremy wrote:
>> holger krekel wrote:
>>> Hi Philippe, 
>> Hi Holger,
>>
>>> On Tue, Apr 28, 2009 at 13:37 +0200, Philippe Fremy wrote:
>>>> Hi,
>>>>
>>>> I was wondering if there is a possibility to have or emulate
>>>> setup/teardown method for an entire directory of tests ?
>>>>
>>>> I have an expensive setup/teardown method, which I share through about
>>>> 10 modules, each with about 20 tests. I would save time if I could do
>>>> the setup/teardown just for that directory.
>>> do you have a setup_module()/teardown_module() pair that 
>>> you import into all your tests?  
>> Exactly.
>>
>>> Do you essentially want to setup the test resource 
>>> only once per test-run? 
>> Once per session would be actually sufficient for this specific case
>> today, but the need is once per test directory.
>>
>> To be a bit more explicit, in my current software development, I have
>> both unit tests for functionality in App1 that I develop myself, and
>> functional tests for a wrapper around App2, which is an external
>> application :
>>
>> base
>> + app1
>>     + tests
>>         + many unit tests
>> + app2_wrapper
>>     + external_app2
>>     + tests
>>         + many functional tests for the app2 wrapper, requiring to setup
>>
>>           a resource for app2 to run.
>>
>> I launch py.test from the base directory.
>>
>> I have an expensive setup/teardown for the functional tests of the app2
>> wrapper, which I would like to share at the app2_wrapper/tests directory
>> level.
>>
>> Ideally, if I run only tests from app1, I don't run that expensive
>> setup/teardown.
>>
>> cheers,
>>
>> Philippe
>>
>> _______________________________________________
>> py-dev mailing list
>> py-dev at codespeak.net
>> http://codespeak.net/mailman/listinfo/py-dev
>>
> 





More information about the Pytest-dev mailing list