Skip to content

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

Open

Description

@remcohaszing

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

Activity

  1. nicoddemus commented on Sep 17, 2016

    @nicoddemus
    Member

    Hey @remcohaszing,

    Sorry, this went under the radar.

    Perhaps it would be better to add this as a pytest.ini option?

    [pytest]
    mock_autospec_default=true
  2. blueyed commented on Sep 17, 2016

    @blueyed
    Contributor

    Adding an option feels dirty to me: then we end up with a lot of them in the end probably?!

    What about overriding the mocker fixture in your conftest to adjust it like you need it (see #37 (comment))?

  3. nicoddemus commented on Sep 18, 2016

    @nicoddemus
    Member

    @blueyed you got a point, we may end up with a lot of options, which doesn't really scale.

    So I'm assuming @blueyed means something like this:

    # content of test_foo.py
    @pytest.fixture
    def mocker(mocker):
        mocker.defaults['autospec'] = True

    The cool thing is that you can adjust the options per-test, per-module, or even the entire test suite:

    # content of conftest.py
    @pytest.fixture(autouse=True)
    def mocker(mocker):
        mocker.defaults['autospec'] = True

    I like it. 😁

  4. changed the title [-]Allow to enable autospec by default[/-] [+]Add a "defaults" dict to mocker to allow changing defaults that are passed to mock.patch[/+] on Mar 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions