pytest-dev / pytest-dev/pytest

Using monkeypatch in non function scoped fixture

Open
#363 28 comments 41 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: monkeypatch type: enhancement
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Originally reported by: BitBucket: ColeVsCode, GitHub: ColeVsCode


Hi, I'd like to be able to create a module or session scoped fixture that uses monkeypatch.

@pytest.fixture(scope='session')
def usermanager(monkeypatch):
    ...

This raises an error. There's some comments about this on the pytest-dev list.

https://mail.python.org/pipermail/pytest-dev/2012-November/002157.html

Is there a work-around in the mean time that I can use to change the scope of the monkeypatch fixture?


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 with the session-scoped fixture example and read the linked pytest-dev discussion; the issue names no repository files, tests, or entry points. Done means establishing an accepted way to use monkeypatch from module- or session-scoped fixtures, or documenting a supported workaround, with coverage for the requested scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.