[TIP] How to use same pytest hook at module and function scopes?
nicoddemus at gmail.com
Wed Feb 8 06:42:57 PST 2017
On Wed, Feb 8, 2017 at 12:22 PM arun kali raja <arunsep886 at gmail.com> wrote:
> I tried couple of things.
> 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?):
> 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:
> 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,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python