You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
take a detailed look at integration with the monkeypatch fixture #9
I'm not sure what you mean, can you clarify your request a bit please? How would you like to extend monkeypatch, and what do you mean by mock integration for pytest should never use mock.patch?
I'm not sure what your overall object is... to integrate pytest-mock into pytest? Unify the implementations? Make pytest-mock use monkeypatch?
While there is overlap, monkeypatch and unittest.mock are not the same. Monkeypatch does simple attribute substitution, replacing attributes and functions, while unittest.mock does that plus it provides a Mock class which you can configure to behave as another class for testing, monitor calls were made to it, etc. pytest-mock is just a convenience around the unittest.mock module for use with pytest (here's the rationale).
my basic understanding is that mock.patch deals with monkeypatching mock objects into places
so its a monkeypatching mechanism distinct from pytest monkeypatch which means monkeypatch and mock.patch do not integrate
i'm not yet after a implementation unification, but i'd like to have things in place that taking mock support into pytest later on is straightforward and well combined
@nicoddemus@RonnyPfannschmidt is this still blocking merging pytest-mock into pytest? With pytest 5 dropping support for platforms without unittest.mock it makes a lot of sense to have it built in
On Fri, 5 Jul 2019, 15:26 Bruno Oliveira, ***@***.***> wrote:
@graingert <https://github.com/graingert> I'm not sure, because now users
will have two builtin options, monkeypatch and mocker, which is confusing.
We might think about how to integrate them instead, for example
monkeypatch.mock might behave like the current mocker fixture:
def test_foo(monkeypatch):
monkeypatch.mock.patch('os.remove')
Or we might decide to add patch and patch.object directly to monkeypatch:
def test_foo(monkeypatch):
monkeypatch.patch('os.remove')
But actually I'm leaning towards leaving outside the core for now.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9?email_source=notifications&email_token=AADFATAP5YQCEDQMAWI7Q2DP55KZBA5CNFSM4A7URDH2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZJU25A#issuecomment-508775796>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADFATGSJCT5UDPXP3LBIGDP55KZBANCNFSM4A7URDHQ>
.
IMO they are widely different: while tmp_path and tmpdir both provide the same temporary directory only changing the type of object returned, monkeypatch and mocker provide completely different interfaces and capabilities: monkeypatch only replaces attributes by an equivalent object, while mocker installs a MagicMock object in-place of existing attributes and adds tons of capabilities, including checking how the mock object was called.
Activity
RonnyPfannschmidt commentedon Apr 9, 2015
after some analysis i came to the conclusion that monkeypatch needs to be extended and a mock integration for pytest should never use mock.patch
nicoddemus commentedon Apr 9, 2015
Hi @RonnyPfannschmidt,
I'm not sure what you mean, can you clarify your request a bit please? How would you like to extend
monkeypatch, and what do you mean by mock integration for pytest should never use mock.patch?RonnyPfannschmidt commentedon Apr 9, 2015
mock.patch maintains a custom set of own monkey-patches which is completely unaware of pytest
monkeypatch is neither context nest-able, nor can it do partial undo
so for a proper integration monkeypatch needs partial undo
nicoddemus commentedon Apr 9, 2015
I'm not sure what your overall object is... to integrate
pytest-mockinto pytest? Unify the implementations? Makepytest-mockusemonkeypatch?While there is overlap,
monkeypatchandunittest.mockare not the same. Monkeypatch does simple attribute substitution, replacing attributes and functions, while unittest.mock does that plus it provides aMockclass which you can configure to behave as another class for testing, monitor calls were made to it, etc.pytest-mockis just a convenience around theunittest.mockmodule for use withpytest(here's the rationale).RonnyPfannschmidt commentedon Apr 9, 2015
my basic understanding is that mock.patch deals with monkeypatching mock objects into places
so its a monkeypatching mechanism distinct from pytest monkeypatch which means monkeypatch and mock.patch do not integrate
i'm not yet after a implementation unification, but i'd like to have things in place that taking mock support into pytest later on is straightforward and well combined
nicoddemus commentedon Apr 9, 2015
monkeypatchhas anundomethod, so implementing support forwithstatement seems straightforward to implement.I'm not sure what you mean by which means monkeypatch and mock.patch do not integrate, since I think this works:
RonnyPfannschmidt commentedon Apr 10, 2015
but a monkeypatch works very different from a mock.patch - for example monkeypatch lacks selective undo
nicoddemus commentedon Apr 10, 2015
That's true
graingert commentedon Jul 5, 2019
@nicoddemus @RonnyPfannschmidt is this still blocking merging pytest-mock into pytest? With pytest 5 dropping support for platforms without
unittest.mockit makes a lot of sense to have it built innicoddemus commentedon Jul 5, 2019
@graingert I'm not sure, because now users will have two builtin options,
monkeypatchandmocker, which is confusing.We might think about how to integrate them instead, for example
monkeypatch.mockmight behave like the currentmockerfixture:Or we might decide to add
patchandpatch.objectdirectly tomonkeypatch:But actually I'm leaning towards leaving outside the core for now.
graingert commentedon Jul 5, 2019
nicoddemus commentedon Jul 5, 2019
IMO they are widely different: while
tmp_pathandtmpdirboth provide the same temporary directory only changing the type of object returned,monkeypatchandmockerprovide completely different interfaces and capabilities:monkeypatchonly replaces attributes by an equivalent object, whilemockerinstalls aMagicMockobject in-place of existing attributes and adds tons of capabilities, including checking how the mock object was called.