Skip to content

Use a callable to define fixture scoped dynamically #1682

@nicoddemus

Description

@nicoddemus

Allow scope parameter of fixtures to receive a callable instead of a string. When a callable, it will be called with the config object (passed as keyword argument) and should return a string, which will determine the scope of the fixture. This function will evaluate only once.

The idea is that developers might be interested to have different scopes for a fixture depending on a command line option, so that one might choose to change a fixture scope to session to avoid costly initialization during development, but opt to change it to function in a C.I. server.

Suggested by @hpk42

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: 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