[pytest-dev] pytest_plugin with session scope fixture

Jens Hoffmann jh at solute.de
Tue Nov 25 07:23:38 CET 2014


Hi Holger,


conftest.py/setuptools works just fine, but many tests require the 
absence of the plugin because of importing/dependency problems. So we 
decided to explicitly declare to use the plugin in every test file (also 
I find this to be a little less indirection).



But anyway, things are as you say; even the so included plugin declares 
its session scope fixtures globally for every test; I doubted on this 
for just a moment, because my test-suite does strange things right now 
(apparently since I introduced that per-file pytest-plugin-declaration).



But thank you anyway for your quick response!
Jens



On 11/24/2014 05:18 PM, holger krekel wrote:
> Hi Jens,
>
> On Mon, Nov 24, 2014 at 13:57 +0100, Jens Hoffmann wrote:
>> Hi everybody,
>>
>> I have a problem concering the following setup:
>>
>> - I have written a pytest plugin defining a session scope fixture
>> - in my test files - say ./test/a/test_foo.py and
>> ./test/b/test_bar.py I ``import'' the pytest plugin via declaring
>> the pytest_plugins variable: pytest_plugins = 'my.cool.plugin'
>>
>>
>> So, there's no conftest.py - say below ./test, that declares
>> my.cool.plugin ``globally'' for test/a and test/b
>>
>>
>>
>> What is the session scope in this setup when I run ``py.test test''
>> on the command line? Is the scope split in test/a and test/b or do
>> we still have a ``real'' session scope for everything below test?
> "my.cool.plugin" will have a "global" session scope which means test/a
> and test/b will share the same session-scoped fixture instances.
>
>> My real but similar setup seems to split the scope into chunks of
>> modules which contain test files which declare pytest_plugins... but
>> may be I am wrong...
>> Is that possible?
> I don't understand the question, sorry.
> Also I am not sure why you use the indirection of "pytest_plugins".
> why do conftest.py files or setuptools-installed plugijns not work for you?
>
> holger



More information about the pytest-dev mailing list