Commit Graph

45 Commits

Author SHA1 Message Date
Xtreak 9c3f284de5 Autospec functions should propagate mock calls to parent GH-11273 2019-02-25 21:46:34 +00:00
Susan Su 2bdd5858e3 bpo-35500: align expected and actual calls on mock.assert_called_with error message. (GH-11804) 2019-02-13 18:22:29 -08:00
Pablo Galindo 222d303ade bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)
* Allow repeated deletion of unittest.mock.Mock attributes

* fixup! Allow repeated deletion of unittest.mock.Mock attributes

* fixup! fixup! Allow repeated deletion of unittest.mock.Mock attributes
2019-01-21 08:57:46 +00:00
Mario Corchero f05df0a4b6 bpo-35330: Don't call the wrapped object if `side_effect` is set (GH10973)
* tests: Further validate `wraps` functionality in `unittest.mock.Mock`

Add more tests to validate how `wraps` interacts with other features of
mocks.

* Don't call the wrapped object if `side_effect` is set

When a object is wrapped using `Mock(wraps=...)`, if an user sets a
`side_effect` in one of their methods, return the value of `side_effect`
and don't call the original object.

* Refactor what to be called on `mock_call`

When a `Mock` is called, it should return looking up in the following
order: `side_effect`, `return_value`, `wraps`. If any of the first two
return `mock.DEFAULT`, lookup in the next option.

It makes no sense to check for `wraps` returning default, as it is
supposed to be the original implementation and there is nothing to
fallback to.
2018-12-08 11:25:02 +00:00
Andrew Dunai e63e617ebb bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (#10873)
Fix minor typo in test function name.
2018-12-04 09:08:45 +00:00
Chris Withers 8ca0fa9d2f
bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)
Also refactor the call recording imolementation and add some notes
about its limitations.
2018-12-03 21:31:37 +00:00
Xtreak edeca92c84 bpo-31177: Skip deleted attributes while calling reset_mock (GH-9302) 2018-12-01 11:03:54 +01:00
Petter Strandmark 47d94241a3 bpo-35047, unittest.mock: Better error messages on assert_called_xxx failures (GH-10090)
unittest.mock now includes mock calls in exception messages if
assert_not_called, assert_called_once, or assert_called_once_with
fails.
2018-10-28 21:37:10 +01:00
Tony Flury 2087023fde bpo-32933: Implement __iter__ method on mock_open() (GH-5974) 2018-09-13 01:21:16 +03:00
Serhiy Storchaka a203360836 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:15:18 +02:00
Serhiy Storchaka 362f058a89 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:12:58 +02:00
Kushal Das 9cd39a170b Issue #21271: Adds new keyword only parameters in reset_mock call
We now have two keyword only parameters in the reset_mock function to
selectively reset the return_value or the side_effects, or both.
2016-06-02 10:20:16 -07:00
Robert Collins c85dd85f1a Issue #26807: mock_open 'files' no longer error on readline at end of file.
Patch from Yolanda Robla.
2016-05-16 15:22:45 +12:00
Robert Collins 9549a3e3d4 Issue #26807: mock_open 'files' no longer error on readline at end of file.
Patch from Yolanda Robla.
2016-05-16 15:22:01 +12:00
Berker Peksag 5a6c018b57 Issue #25195: Fix a regression in mock.MagicMock
_Call is a subclass of tuple (changeset 3603bae63c13 only works
for classes) so we need to implement __ne__ ourselves.

Patch by Andrew Plummer.
2016-03-28 00:30:40 +03:00
Berker Peksag ce913877e4 Issue #25195: Fix a regression in mock.MagicMock
_Call is a subclass of tuple (changeset 3603bae63c13 only works
for classes) so we need to implement __ne__ ourselves.

Patch by Andrew Plummer.
2016-03-28 00:30:02 +03:00
Victor Stinner 2c2a4e63d7 Add Mock.assert_called()
Issue #26323: Add assert_called() and assert_called_once() methods to
unittest.mock.Mock.
2016-03-11 22:17:48 +01:00
Berker Peksag 29bf4d403d Issue #24857: Comparing call_args to a long sequence now correctly returns a
boolean result instead of raising an exception.

Patch by A Kaptur.
2015-09-09 23:39:45 +03:00
Berker Peksag 3fc536f1c9 Issue #24857: Comparing call_args to a long sequence now correctly returns a
boolean result instead of raising an exception.

Patch by A Kaptur.
2015-09-09 23:35:25 +03:00
Robert Collins ca647ef60a Issue #21750: Further fixup to be styled like other mock APIs. 2015-07-24 03:48:20 +12:00
Robert Collins 5329aaa74b Issue #21750: mock_open.read_data can now be read from each instance, as it
could in Python 3.3.
2015-07-17 20:08:45 +12:00
Robert Collins b37f43f94b - Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
Patch from Nicola Palumbo and Laurent De Buyst.
2015-07-15 11:42:28 +12:00
Robert Collins 88ba360c88 Issue #21750: Further fixup to be styled like other mock APIs. 2015-07-24 03:48:45 +12:00
Robert Collins 4838717b53 Issue #21750: mock_open.read_data can now be read from each instance, as it
could in Python 3.3.
2015-07-17 20:10:23 +12:00
Robert Collins 76d508b5d4 - Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.
Patch from Nicola Palumbo and Laurent De Buyst.
2015-07-15 11:49:43 +12:00
Robert Collins f58f88c4c7 Issue #23661: unittest.mock side_effects can now be exceptions again.
This was a regression vs Python 3.4. Patch from Ignacio Rossi
2015-07-14 13:51:40 +12:00
Kushal Das a37b958d65 Closes #21270 : We now override tuple methods in mock.call objects. 2014-09-16 18:33:37 +05:30
R David Murray 130a566a13 Suppress a couple more DeprecationWarnings in the test suite. 2014-06-11 17:09:43 -04:00
Kushal Das 047f14c3c6 Closes #21256: Printout of keyword args in deterministic order in mock calls.
Printout of keyword args should be in deterministic order in
a mock function call. This will help to write better doctests.
2014-06-09 13:45:56 +05:30
Kushal Das 484f8a875b Closes Issue 21222.
Passing name keyword argument to mock.create_autospec now works.
2014-04-16 01:05:50 +05:30
Kushal Das 8af9db3e4f Closes Issue 21262: New method assert_not_called for Mock.
It raises AssertionError if the mock has been called.
2014-04-17 01:36:14 +05:30
Kushal Das 8c14534df6 Closes Issue 21238: New keyword argument `unsafe` to Mock.
It raises `AttributeError` incase of an attribute startswith assert
or assret.
2014-04-16 23:32:21 +05:30
Michael Foord 01bafdcccc Issue 17826. Setting an iterable side_effect on a mock created by create_autospec now works 2014-04-14 16:09:42 -04:00
Michael Foord 514afeb65c Merge 2013-11-23 13:30:03 +00:00
Serhiy Storchaka bc39869095 Issue #19594: Use specific asserts in unittest tests. 2013-11-17 00:14:35 +02:00
Serhiy Storchaka 5665bc5980 Issue #19594: Use specific asserts in unittest tests. 2013-11-17 00:12:21 +02:00
Michael Foord 468ec34084 Remove shadowed test 2013-09-15 20:05:19 +12:00
Antoine Pitrou 356bdeb0a1 Issue #19013: add unittest.main() epilogs to unittest.mock's own test modules 2013-09-13 23:54:01 +02:00
Andrew Svetlov 8ab1e513c1 Process DEFAULT values in mock side_effect that returns iterator.
Patch by Michael Ford.
2013-04-07 16:44:07 +03:00
Andrew Svetlov 8b2cd75bdd Process DEFAULT values in mock side_effect that returns iterator.
Patch by Michael Ford.
2013-04-07 16:42:24 +03:00
Antoine Pitrou 5c64df70b5 Issue #17015: When it has a spec, a Mock object now inspects its signature when matching calls, so that arguments can be matched positionally or by name. 2013-02-03 00:23:58 +01:00
Michael Foord 28d591ceef Closes issue 15323. Improve failure message of Mock.assert_called_once_with 2012-09-28 16:15:22 +01:00
Michael Foord 2cd48738ba Closes issue 14636. mock objects raise exceptions from an iterable side_effect 2012-04-21 15:52:11 +01:00
Michael Foord 83a16856ee Fix another mock import 2012-03-14 12:58:46 -07:00
Michael Foord 345266aa7e PEP 417: Adding unittest.mock 2012-03-14 12:24:34 -07:00