mocker.stop(m)method to stop specific
AsyncMocksupport for Python 3.7+ in
Fixed regression caused by an explicit
mockdependency in the code (#298).
MockerFixture.async_mockmethod. Thanks @PerchunPak for the PR (#296).
Python 3.10 now officially supported.
Dropped support for Python 3.6.
pytest-mock no longer supports Python 3.5.
Correct type annotations for
mocker.patch.objectto also include the string form. Thanks @plannigan for the PR (#235).
side_effectkeyword arguments. Thanks @alex-marty for the PR (#214).
inspect.getattr_staticinstead of resorting to
object.__getattribute__magic. This should better comply with objects which implement a custom descriptor protocol. Thanks @yesthesoup for the PR (#224).
Now all patch functions will emit a warning instead of raising a
ValueErrorwhen used as a context-manager. Thanks @iforapsy for the PR (#221).
mocker.patch.context_manageris available when the user intends to mock a context manager (for example
threading.Lockobject), which will not emit that warning.
Add mock.seal alias to the mocker fixture (#211). Thanks @coiax for the PR.
Fixed spying on exceptions not covered by the
Exceptionsuperclass (#215), like
KeyboardInterrupt– PR #216 by @webknjaz.
Before the fix, both
spy_exceptionwere always assigned to
Nonewhenever such an exception happened. And after this fix,
spy_exceptionis set to a correct value of an exception that has actually happened.
MockFixtureas an alias to
3.3.0, the fixture class was named
MockFixture, but was renamed to
MockerFixtureto better match the
mockerfixture. While not officially part of the API, it was later discovered that this broke the code of some users which already imported
pytest_mock.MockFixturefor type annotations, so we decided to reintroduce the name as an alias.
Note however that this is just a stop gap measure, and new code should use
MockerFixturefor type annotations.
Improved typing for
MockerFixture.patch(#201). Thanks @srittau for the PR.
pytest-mocknow includes inline type annotations and exposes them to user programs. The
pytest_mock.MockerFixture, which can be used to annotate your tests:
from pytest_mock import MockerFixture def test_foo(mocker: MockerFixture) -> None: ...
The type annotations were developed against mypy version
0.782, the minimum 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).
AsyncMock is now exposed in
mockerand supports provides assertion introspection similar to
Added by @tirkarthi in #197.
Fixed performance regression caused by the
mockeris used as context manager (#191).
Python 2.7 and 3.4 are no longer supported. Users using
pip 9or later will install a compatible version automatically.
mocker.spynow also works with
async deffunctions (#179). Thanks @frankie567 for the PR!
mocker.spyattributes for tracking returned values and raised exceptions of its spied functions are now called
spy_exception, instead of reusing the existing
1.13introduced a serious regression: after a spied function using
mocker.spyraises an exception, further calls to the spy will not call the spied function, always raising the first exception instead: assigning to
unittest.mockto behave this way (#175).
mockalias to the
mockerfixture has finally been removed.
The object returned by
mocker.spynow also tracks any side effect of the spied method/function.
Fix error if
mocker.patchis used in code where the source file is not available, for example stale
Now all patch functions also raise a
ValueErrorwhen used as a context-manager. Thanks @AlexGascon for the PR (#168).
The pytest introspection follows message is no longer shown if there is no pytest introspection (#154). Thanks @The-Compiler for the report.
mockernow raises a
ValueErrorwhen used as a context-manager. Thanks @binarymason for the PR (#165).
The object returned by
mocker.spynow also tracks the return value of the spied method/function.
Fix plugin when ‘terminal’ plugin is disabled
Fix broken links and update README. Also the code is now formatted using black.
pytest-mockno longer supports Python 2.6 and Python 3.3, following the lead of
pytestand other projects in the community. Thanks @hugovk for the PR (#96).
Some tests in
pytest-mock’s suite are skipped if assertion rewriting is disabled (#102).
UnicodeDecodeErrorduring assert introspection in
assert_called_within Python 2. Thanks @AndreasHogstrom for the report (#91).
Provide source package in
tar.gzformat and remove obsolete
The original assertions raised by the various
Mock.assert_*methods now appear in the failure message, in addition to the message obtained from pytest introspection. Thanks @quodlibetor for the initial patch (#79).
New configuration variable,
False). This forces the plugin to import
unittest.mockon Python 3. This is useful to import a newer version than the one available in the Python distribution.
Previously the plugin would first try to import
mockand fallback to
unittest.mockin case of an
ImportError, but this behavior has been removed because it could hide hard to debug import errors (#68).
mock(Python 2) and
unittest.mock(Python 3) are lazy-loaded to make it possible to implement the new
mock_use_standlone_moduleconfiguration option. As a consequence of this the undocumented
pytest_mock.mock_modulevariable, which pointed to the actual mock module being used by the plugin, has been removed.
DEFAULT is now available from the
Add support for Python 3.6. Thanks @hackebrot for the report (#59).
mock.mock_openis now aliased as
mocker.mock_openfor convenience. Thanks @pokidovea for the PR (#66).
Try to import
mockfirst instead of
unittest.mock. This gives the user flexibility to install a newer
mockversion from PyPI instead of using the one available in the Python distribution. Thanks @wcooley for the PR (#54).
mock.sentinelis now aliased as
mocker.sentinelfor convenience. Thanks @kjwilcox for the PR (#56).
From this version onward,
pytest-mockis licensed under the MIT license (#45).
Now the plugin also adds introspection information on differing call arguments when calling helper methods such as
assert_called_once_with. The extra introspection information is similar to pytest’s and can be disabled with the
mock_traceback_monkeypatchoption. Thanks @asfaltboy for the PR (#36).
mocker.stub()now allows passing in the name for the constructed
Mockobject instead of having to set it using the internal
_mock_nameattribute directly. This is useful for debugging as the name is used in the mock’s
reprstring as well as related assertion failure messages. Thanks @jurko-gospodnetic for the PR (#40).
mockmodule for friendlier tracebacks is automatically disabled with the
--tb=nativeoption. The underlying mechanism used to suppress traceback entries from
mockmodule does not work with that option anyway plus it generates confusing messages on Python 3.5 due to exception chaining (#44). Thanks @blueyed for the report.
mock.callis now aliased as
mocker.callfor convenience. Thanks @jhermann for the PR (#49).
PropertyMock is now accessible from
mocker. Thanks @satyrius for the PR (#32).
Fix regression using one of the
assert_*methods in patched functions which receive a parameter named
method. Thanks @sagarchalise for the report (#31).
Fix regression in frozen tests due to
distutilsimport dependency. Thanks @The-Compiler for the report (#29).
Fix regression when using
pytest-2.7.X. Thanks @akscram for the report (#28).
mocker.resetallfunction, which calls
reset_mock()in all mocked objects up to that point. Thanks to @mathrick for the PR!
pytest-mockis now also available as a wheel. Thanks @rouge8 for the PR!
Thanks to @fogo, mocker.spy can now prey upon staticmethods and classmethods. :smile:
Two new auxiliary methods,
READMEfor usage. (Thanks @fogo for complete PR!)
MagicMockare now accessible from the
mockerfixture, many thanks to @marcwebbie for the complete PR!
mockerfixture now returns the same object (#8). Many thanks to @RonnyPfannschmidt for the PR!
Small fix, no longer using wheel as an alternate package since it conditionally depends on mock module based on Python version, as Python >= 3.3 already includes
unittest.mock. Many thanks to @The-Compiler for letting me know and providing a PR with the fix!
Small release that just uses
pytest_mockas the name of the plugin, instead of
pytest-mock: this makes it simple to depend on this plugin explicitly using
pytest_pluginsmodule variable mechanism.
Fixed bug #2, where a patch would not be uninstalled correctly after patching the same object twice.