Hi Philippe,

On Wed, Oct 28, 2009 at 10:09 +0100, Philippe Fremy wrote:
> 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. 
> >   
> I am reviving this old thread.
> 
> Honestly, I haven't tried the funcargs based solution that you propose.
> The reasons are :
> - I would really prefer to have setup/teardown at directory level and
> your solution is more per-session level

true, that's currently the case. 

> - I don't like the idea of modifying 100 tests just to get a
> setup/teardown effect

Sure.  i am thinking about introducing a general "pytest_pyfunc_setup"
hook that you could define at project, directory, module or class level 
and that would be called for setup of each function. 

> - I still find funcargs a bit cumbersome as explained in my other mail.
>
> I had a quick look at the plugin architecture to see if I could
> implement an equivalent of setup/teardown at directory level, but I
> don't think it's possible.

Whatever is called for "directory" setup could live in a conftest.py file.  
The question is how to transfer any "directory" setup state
to a module.  At first i thought one could write down:

    # ./conftest.py 
    def setup_module(mod): 
        # will be called for all modules in/below the dir
        mod.something = "value"

but one would expect this to be called for each module and not
just once for a whole directory.    Now one could perform some
directory-level caching but one conceptual issue remains: 
values would be "magically" injected into the test modules.   

Do you have ideas about how you'd like the API to work? 

> Can you consider this as a feature request ?

i'd like to get an idea on how this could work at all conceptually. 

best,
holger
_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev

Reply via email to