[TIP] How to use same pytest hook at module and function scopes?
Bruno Oliveira
nicoddemus at gmail.com
Wed Feb 8 06:42:57 PST 2017
Hi Arun,
On Wed, Feb 8, 2017 at 12:22 PM arun kali raja <arunsep886 at gmail.com> wrote:
>
>
> I tried couple of things.
>
> 1.
>
> declaring configurationBackup in conftest.py as a function level
> fixture)as an autouse fixture). But the problem here is its executed before
> common_configuration fixture for TC_1
>
>
One way to enforce this order is to make the function-level fixture depend
on the module-level fixture (common_configuration?):
@pytest.fixture(scope='module')
def common_configuration():
...
@pytest.fixture(autouse=True)
def function_level_configuration(common_configuration):
...
> 1.
>
> tried using standar pytest hooks. There is a pytest hook
> pytest_runtest_call.. i was thinking if i can decorate this hook function
> with my configurationBackup fixture like this:
>
> @pytest.mark.usefixtures("configurationBackup")
> def pytest_runtest_call(item):
>
>
> But this also doesnt seem to work... my configurationBackup fixture is not
> called at all..
>
This is unfortunately a common source of confusion, but
"@pytest.mark.usefixtures" only works for test items, not fixtures and
hooks. But I believe there's a note about this in the docs.
My previous suggestion should work, this kind of dependency between
fixtures is common and well supported. If it doesn't, it means I probably
didn't understand your problem completely, in which case I would ask to
post a more detailed pseudo-code which better conveys the problem.
Hope this helps,
Bruno.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20170208/51224774/attachment.htm>
More information about the testing-in-python
mailing list