Hi Philippe, Ronny, On Tue, Apr 13, 2010 at 14:19 +0200, Ronny Pfannschmidt wrote: > On Mon, 2010-04-12 at 12:24 +0200, Philippe Fremy wrote: > > > > That thread is 6 months old, but I see that it is still relevant. > > > > holger krekel wrote: > > > Hi Philippe, > > > > > > On Wed, Oct 28, 2009 at 10:09 +0100, Philippe Fremy wrote: > > > > > > > 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? > > > > > > > Yes, I now know how I want to transfer the value. I would like to use > > the py.test namespace. > > > > Today, only pytest_namespace() is available to setup an initial > > namespace. I would like to see a pytest_update_namespace() to pass a > > dict with key/values to put in the namespace. > > > > cheers, > > > > Philippe > > > > How about more control over funcargs > > in particular > > a) caching on various levels of packages > b) exposure of all currently usable funcargs in the py.test namespace
Well, funcargs are well defined when used/requested from a test function. Having them globally available blurs the lines a lot and convolutes the py.test namespace. and what would e.g. py.test.tmpdir even be? would it be different when called from a test func, the various setup functions or used at import time etc.? Getting back to Philippe's goal of having per-directory cached values exposed to test functions i wonder if we could a) introduce a directory scope for funcarg-caching b) allow (a subset of) funcargs for setup functions Given this we could write down something like: # ./test_module.py def setup_module(mod, appserver): mod.appserver = appserver # ./conftest.py def pytest_funcarg__appserver(request): return request.cached_setup( setup=lambda: MyAppServer(...), teardown=lambda x: x.shutdown(), scope="directory" ) However, i am not sure if allowing funcargs in setup functions is sane. Also i am not thrilled about encouraging the use of global variables for transfering information. Maybe implementing a "directory" scope for cached_setup would go a long way. Any test function could then directly use the 'appserver' object as a function argument and rely on its per-directory creation/teardown. best, holger _______________________________________________ py-dev mailing list py-dev@codespeak.net http://codespeak.net/mailman/listinfo/py-dev