[pytest-dev] solving the "too static" fixture scope problem

Florian Schulze florian.schulze at gmx.net
Fri Oct 11 20:46:42 CEST 2013


On 11.10.2013, at 17:58, Ronny Pfannschmidt <ronny.pfannschmidt at gmx.de> wrote:

> Hi Holger,
> 
> i think that just 'each' is too generic,
> i'd rather see something more specific like scope='session,function'
> 
> i think its very important to be in control of the actual scopes used in a fixture
> 
> an example i have in mind is a semi-generic tmpdir fixture
> 
> @pytest.fixture(scope='session,function')
> def tmpdir(request, _pytest_basetmp):
> if request.scope == 'session':
>   return _basetmp.ensure('session', dir=1)
> elif request.scope == 'function':
>   return _basetmp.ensure('tests', dir=1)\
>     .make_numbered_dir(request.function__name__)

If something like this is chosen, then please use a list or tuple, not a comma separated string.

Regards,
Florian Schulze



More information about the Pytest-dev mailing list