Accessories for lamps in pytest 2.3

In the latest version of pytest, it's easy to create devices that are functions, classes, modules, or sessions, such as:

@pytest.fixture(scope="module") def db(): return DB() 

This creates a device that will only be called once for each python module in which it is used.

But what about fixtures that need to be called once per python package? (With the nose, this can be done using the setUp / tearDown methods in the __init__.py package)

+7
source share
1 answer

For appliances at the package level or at the directory level, you can declare the device in the conftest.py file in the directory where you need it using scope='session' . The device will be created after the first test in the catalog. Here is an example. However, if the fixture function registers the finalizer, you can see that it does not execute right after the last test in this directory. I think that pytest could be done to support a more impatient disconnect or to introduce a "directory" area if necessary. Usually this is not a big problem if the breaks are performed a bit later, if they are not executed too early :) Please also note that, apparently, Jason intends to refuse the package - support for the support / gap level for the nose

In any case, if you have a need for a more efficient / accurate breakout of pytest, feel free to open the problem .

+5
source

All Articles