Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
remcohaszing opened this issue Jul 14, 2016 · 3 comments

Comments

@remcohaszing
Copy link

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
@nicoddemus
Copy link
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

@blueyed
Copy link
Contributor

blueyed commented Sep 17, 2016

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))?

@nicoddemus
Copy link
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. 😁

@nicoddemus nicoddemus 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 Mar 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants