Skip to content

Enable fixture dynamic scoping during test run #6101

Open
@rnetser

Description

@rnetser

pytest version 5.2.2

Tried to use dynamic scopes for fixtures. However, the scope definition is executed only once - during the fixture definition.
We would like to have option to control fixture scope during test run.
This will allow code re-use in tests which need the code in different scope.
For example: set up a docker - one test needs it in function level and a separate test needs it in module level.

@pytest.fixture()
def some_fixture():
    pass

# test_method.py
@pytest.mark.scope('some_fixture', 'module')
def test_method(some_fixture):
    pass

# test_function.py
@pytest.mark.scope('some_fixture', 'function')
def test_method(some_fixture):
    pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: fixturesanything involving fixtures directly or indirectlytype: proposalproposal for a new feature, often to gather opinions or design the API around the new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions