Skip to content

Advice request: monkeypatch vs mock.patch #4576

@dimaqq

Description

@dimaqq

I'm working on a codebase where tests use a mixture of mock.patch and pytest's monkeypatch, seemingly based on authors' personal preferences.

The official docs for the latter, https://docs.pytest.org/en/latest/monkeypatch.html, refer to a blog post that's nearing its 10th anniversary; meanwhile the earlier made it into Python proper.

I wonder if there's official advice, like "use X", or perhaps "if you need feature Y, use Z" to choose between the two.

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: monkeypatchrelated to the monkeypatch builtin plugintype: docsdocumentation improvement, missing or needing clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions