- Fix error if
mocker.patch
is used in code where the source file is not available, for example stale.pyc
files (#169).
- Now all patch functions also raise a
ValueError
when 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.
mocker
now raises aValueError
when used as a context-manager. Thanks @binarymason for the PR (#165).
- Fix
mocker.spy
on Python 2 when used on non-function objects which implement__call__
(#157). Thanks @pbasista for the report.
- The object returned by
mocker.spy
now also tracks the return value of the spied method/function.
- Fix plugin when 'terminal' plugin is disabled
- Fix bug at the end of the test session when a call to
patch.stopall
is done explicitly by user code. Thanks @craiga for the report (#137).
- Fix broken links and update README. Also the code is now formatted using black.
- Add support for the recently added
assert_called
method in Python 3.6 andmock-2.0
. Thanks @rouge8 for the PR (#115).
- Add support for the recently added
assert_called_once
method in Python 3.6 andmock-2.0
. Thanks @rouge8 for the PR (#113).
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
Internal
- Some tests in
pytest-mock
's suite are skipped if assertion rewriting is disabled (#102).
- Fix
UnicodeDecodeError
during assert introspection inassert_called_with
in Python 2. Thanks @AndreasHogstrom for the report (#91).
- Provide source package in
tar.gz
format and remove obsoleteMANIFEST.in
.
- Fix
mocker.resetall()
by ignoring mocker objects which don't have aresetall
method, like for examplepatch.dict
. Thanks @jdavisp3 for the PR (#88).
- 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
mocker.mock_module
variable points to the underlying mock module being used (unittest.mock
ormock
). Thanks @blueyed for the request (#71).
- New configuration variable,
mock_use_standalone_module
(defaults toFalse
). This forces the plugin to importmock
instead ofunittest.mock
on 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
mock
and fallback tounittest.mock
in case of anImportError
, but this behavior has been removed because it could hide hard to debug import errors (#68). - Now
mock
(Python 2) andunittest.mock
(Python 3) are lazy-loaded to make it possible to implement the newmock_use_standlone_module
configuration option. As a consequence of this the undocumentedpytest_mock.mock_module
variable, which pointed to the actual mock module being used by the plugin, has been removed. - DEFAULT is now available from
the
mocker
fixture.
- 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).
- Try to import
mock
first instead ofunittest.mock
. This gives the user flexibility to install a newermock
version from PyPI instead of using the one available in the Python distribution. Thanks @wcooley for the PR (#54). mock.sentinel
is now aliased asmocker.sentinel
for convenience. Thanks @kjwilcox for the PR (#56).
- From this version onward,
pytest-mock
is 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 themock_traceback_monkeypatch
option. Thanks @asfaltboy for the PR (#36). mocker.stub()
now allows passing in the name for the constructed Mock object instead of having to set it using the internal_mock_name
attribute directly. This is useful for debugging as the name is used in the mock'srepr
string as well as related assertion failure messages. Thanks @jurko-gospodnetic for the PR (#40).- Monkey patching
mock
module for friendlier tracebacks is automatically disabled with the--tb=native
option. The underlying mechanism used to suppress traceback entries frommock
module 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.call
is now aliased asmocker.call
for convenience. Thanks @jhermann for the PR (#49).
- Fix AttributeError with
mocker.spy
when spying on inherited methods (#42). Thanks @blueyed for the PR.
- 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 namedmethod
. Thanks @sagarchalise for the report (#31).
- Fix regression in frozen tests due to
distutils
import dependency. Thanks @The-Compiler for the report (#29). - Fix regression when using
pytest-mock
withpytest-2.7.X
. Thanks @akscram for the report (#28).
pytest-mock
now monkeypatches themock
library to improve pytest output for failures of mock call assertions likeMock.assert_called_with()
. Thanks to @Chronial for idea and PR (#26, #27)!
- New
mocker.resetall
function, which callsreset_mock()
in all mocked objects up to that point. Thanks to @mathrick for the PR!
pytest-mock
is now also available as a wheel. Thanks @rouge8 for the PR!
Thanks to @fogo, mocker.spy can now prey upon staticmethods and classmethods. 😄
- Two new auxiliary methods,
spy
andstub
. SeeREADME
for usage. (Thanks @fogo for complete PR!)
Mock
andMagicMock
are now accessible from themocker
fixture, many thanks to @marcwebbie for the complete PR!
mocker
fixture 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_mock
as the name of the plugin, instead ofpytest-mock
: this makes it simple to depend on this plugin explicitly usingpytest_plugins
module variable mechanism.
Changed fixture name from
mock
intomocker
because it conflicted with the actual mock module, which made using it awkward when access to both the module and the fixture were required within a test.
- Fixed bug #2, where a patch would not be uninstalled correctly after patching the same object twice.
- Added
patch.dict
support.
First release.