[TIP] How to use same pytest hook at module and function scopes?
arun kali raja
arunsep886 at gmail.com
Wed Feb 8 06:19:56 PST 2017
I am new to pytest and trying to use pytest for my testing purpose.
The TestCase layout which i have is
Now i have a requirement to take backup of configuration before each TC and
also before common_configuration is done and restore it after all the TCs
i am planning to declare common_configuration itself as a module level
For the configuration backup and reversal part, i am trying to implement
that also as fixtures(and its finaliser to reverse configuration)..
So the flow i am trying to achieve is
configurationBackup.finalizer(which is done before common_Configuration)
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
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:
But this also doesnt seem to work... my configurationBackup fixture is not
called at all..
Any other ways to solve this usecase?
I understand that a session level fixture can be called
from module level..(so from lower scope we can call higher scope
fixture)..I tried declaring the configuration Backup as session level
fixture and calling it from module scope/function scope.. but the fixture
was called once in session scope and was not called again in module scope..
can the same fixture be called at two levels?
பா. அருண் காளி ராசா
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python