pytest-dev / pytest-dev/pytest-mock

Add a "defaults" dict to mocker to allow changing defaults that are passed to mock.patch

Open
#55 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
2k
Forks
173
Avg merge
1d 10h
Merged PRs (30d)
6

Description

I always use autospec=True in when patching objects. I think this helps to uncover bad mock calls.

Perhaps it would be nice to be able to set this as a default value. E.g.:

def pytest_configure(mocker_config):
    mocker_config.default_autospec = True

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 tracing the mocker configuration entry point and how defaults are passed to mock.patch. Define how a configuration hook such as pytest_configure(mocker_config) would set default_autospec, then verify that subsequent patch calls use it without preventing per-call overrides. Done means the default behavior and override behavior are covered by focused tests.

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
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.