pytest-dev / pytest-dev/pytest

Enable fixture dynamic scoping during test run

Open
#6,101 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

topic: fixtures type: proposal
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the dynamic-scope example on pytest 5.2.2 and trace where fixture scope is evaluated; the issue names no files or tests. Done means fixture scope can be selected per test run as shown, while preserving the existing fixture behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.