[TIP] How to use same pytest hook at module and function scopes?
arun kali raja
arunsep886 at gmail.com
Wed Feb 8 10:56:16 PST 2017
yeah this will solve the case of calling the fixture(which doesnt do
function level configuration but rather it takes the backup of certain
files in the system before the TC executes and restores them to original
state after the TC is complete) before each TC execution .
But i need the same to be called before the common_configuration part as
well like below:
configurationBackup.finalizer(which is done before common_Configuration)
My hurdle is to handle both these cases thorugh single fixture itself..
As for the fixture for a hook i think i misunderstud modularity funda,
where a fixture can use another fixture and tried to apply the same to a
hook.. my bad!!
On 8 February 2017 at 20:12, Bruno Oliveira <nicoddemus at gmail.com> wrote:
> Hi Arun,
> On Wed, Feb 8, 2017 at 12:22 PM arun kali raja <arunsep886 at gmail.com>
>> 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?):
> def common_configuration():
> def function_level_configuration(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