[TIP] How to use same pytest hook at module and function scopes?

Bruno Oliveira nicoddemus at gmail.com
Wed Feb 8 11:20:28 PST 2017


Hi Arun,

On Wed, Feb 8, 2017 at 4:56 PM arun kali raja <arunsep886 at gmail.com> wrote:

> Hi Bruno,
>
> 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
> common_Configuration
> configurationBackup
> TC_1
> configurationBackup.finalizer
> configurationBackup
> TC_2
> configurationBackup.finalizer
> configurationBackup
> TC_3
> configurationBackup.finalizer
> configurationBackup.finalizer(which is done before common_Configuration)
>
>
>
>
If I understand your example correctly, you can use two fixtures then:

@pytest.fixture(scope='session')
def module_config():
    configurationBackup
    common_Configuration
    yield
    configurationBackup.finalizer


@pytest.fixture(autouse=True)
def function_config(module_config):
    configurationBackup
    yield
    configurationBackup.finalizer

module_config's "configurationBackup.finalizer" will be called last for the
module, after TC_3's "configurationBackup.finalizer".

Cheers,
Bruno.

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20170208/583ef6d8/attachment.htm>


More information about the testing-in-python mailing list