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

Vyacheslav Rafalskiy rafalskiy at gmail.com
Mon May 30 20:24:57 CEST 2011


On Sun, May 29, 2011 at 3:59 AM, holger krekel <holger at merlinux.eu> wrote:
> Hey again,
>
> 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.

Vyacheslav



More information about the Pytest-dev mailing list