Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
==1.2
->==3.14.0
Release Notes
pytest-dev/pytest-mock (pytest-mock)
v3.14.0
Compare Source
#​415 <https://github.com/pytest-dev/pytest-mock/pull/415>
_:MockType
andAsyncMockType
can be imported frompytest_mock
for type annotation purposes.#​420 <https://github.com/pytest-dev/pytest-mock/issues/420>
_: Fixed a regression which would causemocker.patch.object
to not being properly cleared between tests.v3.13.0
Compare Source
#​417 <https://github.com/pytest-dev/pytest-mock/pull/417>
_:spy
now hasspy_return_list
, which is a list containing all the values returned by the spied function.pytest-mock
now requirespytest>=6.2.5
.#​410 <https://github.com/pytest-dev/pytest-mock/pull/410>
: pytest-mock'ssetup.py
file is removed.If you relied on this file, e.g. to install pytest using
setup.py install
,please see
Why you shouldn't invoke setup.py directly <https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html#summary>
for alternatives.v3.12.0
Compare Source
mocker.resetall()
now also resets mocks created bymocker.create_autospec
(#390
_)... _#390:https://github.com/pytest-dev/pytest-mock/pull/3900
v3.11.1
Compare Source
(This release source code is identical to
3.11.0
except a small internal fix to deployment/CI)Fixed introspection for failed
assert_has_calls
(#365
_).Updated type annotations for
mocker.patch
andmocker.spy
(#364
_)... _#365:https://github.com/pytest-dev/pytest-mock/pull/3655
.. _#364https://github.com/pytest-dev/pytest-mock/pull/36464
v3.11.0
Compare Source
Fixed introspection for failed
assert_has_calls
(#365
_).Updated type annotations for
mocker.patch
andmocker.spy
(#364
_)... _#365:https://github.com/pytest-dev/pytest-mock/pull/3655
.. _#364https://github.com/pytest-dev/pytest-mock/pull/36464
v3.10.0
Compare Source
mocker.stop(m)
method to stop specificmocker.patch
ormocker.spy
calls (#319
_)... _#319:https://github.com/pytest-dev/pytest-mock/pull/3199
v3.9.0
Compare Source
NonCallableMagicMock
via themocker
fixture (#318
_)... _#318:https://github.com/pytest-dev/pytest-mock/pull/3188
v3.8.2
Compare Source
AsyncMock
support for Python 3.7+ inmocker.async_stub
(#302
_)... _#302:https://github.com/pytest-dev/pytest-mock/pull/3022
v3.8.1
Compare Source
mock
dependency in the code (#298
_)... _#298:https://github.com/pytest-dev/pytest-mock/issues/2988
v3.8.0
Compare Source
MockerFixture.async_mock
method. Thanks@PerchunPak
_ for the PR (#296
_)... _@PerchunPak: https://github.com/PerchunPak
.. https://github.com/pytest-dev/pytest-mock/pull/296pull/296
v3.7.0
Compare Source
v3.6.1
Compare Source
mocker.resetall()
when usingmocker.spy()
(#237
). Thanks@blaxter
for the report and@shadycuz
_ for the PR... _@blaxter: https://github.com/blaxter
.. _@shadycuz: https://github.com/shady[https://github.com/pytest-dev/pytest-mock/issues/237](https://github.com/pytest-dev/pytest-mock/issues/237)mock/issues/237
v3.6.0
Compare Source
pytest-mock no longer supports Python 3.5.
Correct type annotations for
mocker.patch.object
to also include the string form.Thanks
@plannigan
_ for the PR (#235
_).reset_all
now supportsreturn_value
andside_effect
keyword arguments. Thanks@alex-marty
_ for the PR (#214
_)... _@alex-marty: https://github.com/alex-marty
.. _@plannigan: https://github.com/planni[https://github.com/pytest-dev/pytest-mock/pull/214](https://github.com/pytest-dev/pytest-mock/pull/214)t-mock/pull[https://github.com/pytest-dev/pytest-mock/pull/235](https://github.com/pytest-dev/pytest-mock/pull/235)st-mock/pull/235
v3.5.1
Compare Source
inspect.getattr_static
instead of resorting toobject.__getattribute__
magic. This should better comply with objects which implement a custom descriptor
protocol. Thanks
@yesthesoup
_ for the PR (#224
_)... _@yesthesoup: https://github.com/yesthesoup
.. https://github.com/pytest-dev/pytest-mock/pull/224pull/224
v3.5.0
Compare Source
Now all patch functions will emit a warning instead of raising a
ValueError
when usedas a context-manager. Thanks
@iforapsy
_ for the PR (#221
_).Additionally,
mocker.patch.context_manager
is available when the user intends to mocka context manager (for example
threading.Lock
object), which will not emit thatwarning.
.. _@iforapsy: https://github.com/iforapsy
.. https://github.com/pytest-dev/pytest-mock/pull/221pull/221
v3.4.0
Compare Source
Add
mock.seal
alias to themocker
fixture (#211
). Thanks@coiax
for the PR.Fixed spying on exceptions not covered by the
Exception
superclass (
#215
), likeKeyboardInterrupt
-- PR#216
by
@webknjaz
_.Before the fix, both
spy_return
andspy_exception
were always assigned to
None
whenever such an exception happened. And after this fix,
spy_exception
is set to a correct value of an exceptionthat has actually happened.
.. _@coiax: https://github.com/coiax
.. _@webknjaz: https://github.com/sponsors/webkn[https://github.com/pytest-dev/pytest-mock/pull/211](https://github.com/pytest-dev/pytest-mock/pull/211)t-mock/pull[https://github.com/pytest-dev/pytest-mock/issues/215](https://github.com/pytest-dev/pytest-mock/issues/215)-mock/issue[https://github.com/pytest-dev/pytest-mock/pull/216](https://github.com/pytest-dev/pytest-mock/pull/216)est-mock/pull/216
v3.3.1
Compare Source
Introduce
MockFixture
as an alias toMockerFixture
.Before
3.3.0
, the fixture class was namedMockFixture
, but was renamed toMockerFixture
to bettermatch the
mocker
fixture. While not officially part of the API, it was later discovered that this brokethe code of some users which already imported
pytest_mock.MockFixture
for type annotations, so wedecided to reintroduce the name as an alias.
Note however that this is just a stop gap measure, and new code should use
MockerFixture
for type annotations.Improved typing for
MockerFixture.patch
(#201
). Thanks@srittau
for the PR... _@srittau: https://github.com/srittau
.. https://github.com/pytest-dev/pytest-mock/pull/201pull/201
v3.3.0
Compare Source
pytest-mock
now includes inline type annotations and exposes them to user programs. Themocker
fixture returnspytest_mock.MockerFixture
, which can be used to annotate your tests:.. code-block:: python
The type annotations were developed against mypy version
0.782
, theminimum version supported at the moment. If you run into an error that you believe to be incorrect, please open an issue.
Many thanks to
@staticdev
_ for providing the initial patch (#199
_)... _@staticdev: https://github.com/staticdev
.. https://github.com/pytest-dev/pytest-mock/pull/199pull/199
v3.2.0
Compare Source
AsyncMock <https://docs.python.org/3/library/unittest.mock.html#unittest.mock.AsyncMock>
__ is now exposed inmocker
and supports provides assertion introspection similar toMock
objects.Added by
@tirkarthi
_ in#197
_... _@tirkarthi: https://github.com/tirkarthi
.. https://github.com/pytest-dev/pytest-mock/pull/197pull/197
v3.1.1
Compare Source
ValueError
raisedwhen
mocker
is used as context manager (#191
_)... _#191:https://github.com/pytest-dev/pytest-mock/issues/1911
v3.1.0
Compare Source
New mocker fixtures added that allow using mocking functionality in other scopes:
class_mocker
module_mocker
package_mocker
session_mocker
Added by
@scorphus
_ in#182
_... _@scorphus: https://github.com/scorphus
.. https://github.com/pytest-dev/pytest-mock/pull/182pull/182
v3.0.0
Compare Source
Python 2.7 and 3.4 are no longer supported. Users using
pip 9
or later will installa compatible version automatically.
mocker.spy
now also works withasync def
functions (#179
). Thanks@frankie567
for the PR!.. _#179:https://github.com/pytest-dev/pytest-mock/issues/1799
.. _@frankie567: https://github.com/frankie567
v2.0.0
Compare Source
Breaking Changes
++++++++++++++++
mocker.spy
attributes for tracking returned values and raised exceptions of its spied functionsare now called
spy_return
andspy_exception
, instead of reusing the existingMagicMock
attributesreturn_value
andside_effect
.Version
1.13
introduced a serious regression: after a spied function usingmocker.spy
raises an exception, further calls to the spy will not call the spied function,
always raising the first exception instead: assigning to
side_effect
causesunittest.mock
to behave this way (#175
_).The deprecated
mock
alias to themocker
fixture has finally been removed... _#175:https://github.com/pytest-dev/pytest-mock/issues/1755
v1.13.0
Compare Source
mocker.spy
now also tracks any side effectof the spied method/function.
v1.12.1
Compare Source
mocker.patch
is used in code where the source fileis not available, for example stale
.pyc
files (#169
_)... _#169:https://github.com/pytest-dev/pytest-mock/issues/169#issuecomment-5557292655
v1.12.0
Compare Source
ValueError
when usedas a context-manager. Thanks
@AlexGascon
_ for the PR (#168
_)... _@AlexGascon: https://github.com/AlexGascon
.. https://github.com/pytest-dev/pytest-mock/pull/168pull/168
v1.11.2
Compare Source
The pytest introspection follows message is no longer shown
if there is no pytest introspection (
#154
).Thanks
@The-Compiler
for the report.mocker
now raises aValueError
when used as a context-manager.Thanks
@binarymason
_ for the PR (#165
_)... _#154:https://github.com/pytest-dev/pytest-mock/issues/1544
.. _#165https://github.com/pytest-dev/pytest-mock/pull/16565
.. _@binarymason: https://github.com/binarymason
v1.11.1
Compare Source
mocker.spy
on Python 2 when used on non-function objectswhich implement
__call__
(#157
). Thanks@pbasista
forthe report.
.. _#157:https://github.com/pytest-dev/pytest-mock/issues/1577
.. _@pbasista: https://github.com/pbasista
v1.11.0
Compare Source
mocker.spy
now also tracks the return valueof the spied method/function.
v1.10.4
Compare Source
v1.10.3
Compare Source
@hroncok
_ for the report and@blueyed
_ for the PR (#140
_)... _#140:https://github.com/pytest-dev/pytest-mock/pull/1400
.. _@hroncok: https://github.com/hroncok
v1.10.2
Compare Source
patch.stopall
is done explicitly byuser code. Thanks
@craiga
_ for the report (#137
_)... _#137:https://github.com/pytest-dev/pytest-mock/issues/1377
.. _@craiga: https://github.com/craiga
v1.10.1
Compare Source
black <https://github.com/ambv/black>
__.v1.10.0
Compare Source
assert_called
method in Python 3.6 andmock-2.0
. Thanks@rouge8
_ for the PR (#115
_)... _#115:https://github.com/pytest-dev/pytest-mock/pull/1155
v1.9.0
Compare Source
assert_called_once
method in Python 3.6 andmock-2.0
. Thanks@rouge8
_ for the PR (#113
_)... _#113:https://github.com/pytest-dev/pytest-mock/pull/1133
v1.8.0
Compare Source
NonCallableMock
andcreate_autospec
tomocker
. Thanks@mlhamel
_ for the PR (#111
_)... _#111:https://github.com/pytest-dev/pytest-mock/pull/1111
v1.7.1
Compare Source
setup.py
to correctly read theREADME.rst
. Thanks@ghisvail
_ for the fix (#107
_)... _#107:https://github.com/pytest-dev/pytest-mock/issues/1077
v1.7.0
Compare Source
Incompatible change
pytest-mock
no longer supports Python 2.6 and Python 3.3, following the lead ofpytest
and other projects in the community. Thanks@hugovk
_ for the PR (#96
_).Packaging
mock
requirement in Python 2. Thanks@ghisvail
_ for the report (#101
_).Internal
pytest-mock
's suite are skipped if assertion rewriting is disabled (#102
_)... _@ghisvail: https://github.com/ghisvail
.. _@hugovk: https://github.com/hu[https://github.com/pytest-dev/pytest-mock/pull/96](https://github.com/pytest-dev/pytest-mock/pull/96)st-mock/pul[https://github.com/pytest-dev/pytest-mock/issues/101](https://github.com/pytest-dev/pytest-mock/issues/101)-mock/issue[https://github.com/pytest-dev/pytest-mock/issues/102](https://github.com/pytest-dev/pytest-mock/issues/102)t-mock/issues/102
v1.6.3
Compare Source
UnicodeDecodeError
during assert introspection inassert_called_with
in Python 2.Thanks
@AndreasHogstrom
_ for the report (#91
_)... _@AndreasHogstrom: https://github.com/AndreasHogstrom
.. _#91:https://github.com/pytest-dev/pytest-mock/issues/911
v1.6.2
Compare Source
tar.gz
format and remove obsoleteMANIFEST.in
.v1.6.1
Compare Source
mocker.resetall()
by ignoring mocker objects which don't have aresetall
method, like for examplepatch.dict
.Thanks
@jdavisp3
_ for the PR (#88
_)... _@jdavisp3: https://github.com/jdavisp3
.. _#88:https://github.com/pytest-dev/pytest-mock/pull/888
v1.6.0
Compare Source
Mock.assert_*
methodsnow appear in the failure message, in addition to the message obtained from
pytest introspection.
Thanks
@quodlibetor
_ for the initial patch (#79
_)... _@quodlibetor: https://github.com/quodlibetor
.. _#79:https://github.com/pytest-dev/pytest-mock/pull/799
v1.5.0
Compare Source
mocker.mock_module
variable points to the underlying mock module being used(
unittest.mock
ormock
).Thanks
@blueyed
_ for the request (#71
_)... _#71:https://github.com/pytest-dev/pytest-mock/pull/711
v1.4.0
Compare Source
New configuration variable,
mock_use_standalone_module
(defaults toFalse
). This forcesthe plugin to import
mock
instead ofunittest.mock
on Python 3. This is useful to importa newer version than the one available in the Python distribution.
Previously the plugin would first try to import
mock
and fallback tounittest.mock
in case of an
ImportError
, but this behavior has been removed because it could hidehard to debug import errors (
#68
_).Now
mock
(Python 2) andunittest.mock
(Python 3) are lazy-loaded to make it possible toimplement the new
mock_use_standlone_module
configuration option. As a consequence of thisthe undocumented
pytest_mock.mock_module
variable, which pointed to the actual mock modulebeing used by the plugin, has been removed.
DEFAULT <https://docs.python.org/3/library/unittest.mock.html#default>
_ is now available fromthe
mocker
fixture... _#68:https://github.com/pytest-dev/pytest-mock/issues/688
v1.3.0
Compare Source
Add support for Python 3.6. Thanks
@hackebrot
_ for the report (#59
_).mock.mock_open
is now aliased asmocker.mock_open
for convenience.Thanks
@pokidovea
_ for the PR (#66
_)... _@hackebrot: https://github.com/hackebrot
.. _@pokidovea: https://github.com/pokid[https://github.com/pytest-dev/pytest-mock/issues/59](https://github.com/pytest-dev/pytest-mock/issues/59)-mock/issu[https://github.com/pytest-dev/pytest-mock/pull/66](https://github.com/pytest-dev/pytest-mock/pull/66)est-mock/pull/66
Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about these updates again.