[py-dev] setup_directory / xUnit extension? Re: migration from 1.3 to 2.0

holger krekel holger at merlinux.eu
Wed Jun 1 09:57:43 CEST 2011


On Mon, May 30, 2011 at 14:24 -0400, Vyacheslav Rafalskiy wrote:
> On Sun, May 29, 2011 at 3:59 AM, holger krekel <holger at merlinux.eu> wrote:
> > On Sun, May 29, 2011 at 07:43 +0000, holger krekel wrote:
> >> > > good line of reasoning.  It's mostly my intuition making me hesitant
> >> > > to add setup_package like you suggest.  And i wonder what it is about :)
> >> > > Maybe it's that the root namespace of a test directory is often called
> >> > > "testing" or "tests"  (the "test" one is taken by Python stdlib already).
> >> > > And therefore you would end up having to do "import testing" and
> >> > > then use global state with something like "testing.STATE".
> >> > > But i guess this doesn't look so bad to you, does it? :)
> >> > > (The plugin/conftest system is designed such that it hardly
> >> > > requires any imports to manage test state.)
> >> > >
> >> > > Any more opinions on setup_package(package)? If others find it useful
> >> > > as well, i will consider introducing it with pytest-2.1.
> >> >
> >> > I guess I will have to withdraw the idea. Having to explicitly import
> >> > the test package does not look nice at all.
> >> > conftest.py rules!
> >> >
> >> > As to the two alternatives above I'd rather use
> >> > pytest_setup_testloop(config) with direct access to config.
> >>
> >> I am now pondering following your original intention and introduce a
> >> "setup_directory" to be put into conftest.py files.  You could then
> >> access the config object via pytest.config. Would that make sense
> >> to you as well?
> >
> > To elaborate a wee bit:
> >
> > * setup_directory would be guranteed to be called for any test
> >  (both python, doctest or other test) within the directory hierarchy
> >  of the conftest.py dir and before any setup_module/class etc. is called.
> >
> > * teardown_directory would be guranteed to be called when a test
> >  is run that is not in the directory hierarchy.
> >
> > * if neccessary one can have setup_directory push test related
> >  state to some global module (from which tests could import for example)
> >
> > i am not yet sure about the idea but i guess it would be somewhat natural
> > and complete the setup_*/teardown_* xUnit style fixture methods.
> >
> > holger
> 
> Sounds great to me. Not much to add. Perhaps a parameter, say
> directory_config, which
> can then be imported by a test module like for example
> 
> from pytest import directory_config
>
> This object could have different meaning depending on the directory
> where the test module resides.

This suggestion would replicate funcarg-functionality which allows
to provide different/adapted resources to test modules from conftest.py
files.  I'd rather like to think about generally giving access to funcarg
resources from xUnit setup functions which would enlarge what you can
do from xUnit fixtures.

Meanwhile, we could maybe introduce a global "pytest.appdata" object which
can be used for passing state between various places in test like
setup_directory or hooks and test methods or other setup methods.
Several python packages (particularly web stuff) have global data
anyway and maybe it's best to provide one managed storage for it.

best,
holger

> 
> Vyacheslav
> 



More information about the Pytest-dev mailing list