summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
Commit message (Collapse)AuthorAgeFilesLines
...
* Mock 100% coverage (GH-13045)Chris Withers2019-05-011-56/+5
| | | | | | | | | | | This was achieved by: * moving many pass statements in tests onto their own lines, so they pass line coverage and can match an easy ignore pattern if branch coverage is added later. * removing code that cannot be reached. * removing long-disabled tests. * removing unused code. * adding tests for uncovered code It turned out that removing `if __name__ == '__main__'` blocks that run unittest.main() at the bottom of test files was surprisingly contentious, so they remain and can be filtered out with an appropriate .coveragerc.
* remove jython support from unittest.mock (GH#13033)Chris Withers2019-05-011-9/+2
|
* Don't report deleted attributes in __dir__ (GH#10148)Mario Corchero2019-04-301-2/+4
| | | | | | When an attribute is deleted from a Mock, a sentinel is added rather than just deleting the attribute. This commit checks for such sentinels when returning the child mocks in the __dir__ method as users won't expect deleted attributes to appear when performing dir(mock).
* bpo-23078: Add support for {class,static}method to mock.create_autospec() ↵Xtreak2019-04-221-1/+3
| | | | | (GH-11613) Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
* bpo-36593: Fix isinstance check for Mock objects with spec executed under ↵Xtreak2019-04-131-1/+1
| | | | | tracing (GH-12790) In Python having a trace function in effect while mock is imported causes isinstance to be wrong for MagicMocks. This is due to the usage of super() in some class methods, as this sets the __class__ attribute. To avoid this, as a workaround, alias the usage of super .
* bpo-36366: Return None on stopping unstarted patch object (GH-12472)Xtreak2019-03-281-1/+1
| | | | | | Return None after calling unittest.mock.patch.object.stop() regardless of whether the object was started. This makes the method idempotent. https://bugs.python.org/issue36366
* bpo-21269: Provide args and kwargs attributes on mock call objects GH11807Kumar Akshay2019-03-221-0/+16
|
* Autospec functions should propagate mock calls to parent GH-11273Xtreak2019-02-251-0/+8
|
* bpo-35512: Resolve string target to patch.dict decorator during function ↵Xtreak2019-02-241-2/+2
| | | | | | | | | | | | | | call GH#12000 * Resolve string target to patch.dict during function call * Add NEWS entry * Remove unneeded call * Restore original value for support.target and refactor assertions * Add extra assertion to verify unpatched dict
* bpo-35500: align expected and actual calls on mock.assert_called_with error ↵Susan Su2019-02-141-2/+5
| | | | message. (GH-11804)
* bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)Pablo Galindo2019-01-211-4/+3
| | | | | | | | * 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
* Fix mock_open docstring to use readline (#11176)Xtreak2018-12-201-1/+1
|
* bpo-17185: Add __signature__ to mock that can be used by inspect for ↵Xtreak2018-12-121-2/+4
| | | | | | | | | | | | | | | | signature (GH11048) * Fix partial and partial method signatures in mock * Add more calls * Add NEWS entry * Use assertEquals and fix markup in NEWS * Refactor branching and add markup reference for functools * Revert partial object related changes and fix pr comments
* bpo-35330: Don't call the wrapped object if `side_effect` is set (GH10973)Mario Corchero2018-12-081-11/+10
| | | | | | | | | | | | | | | | | | | | | | | * 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.
* bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of ↵Andrew Dunai2018-12-041-14/+14
| | | | | _Call/_MagicProxy. (#10873) Fix minor typo in test function name.
* bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)Chris Withers2018-12-031-23/+32
| | | | Also refactor the call recording imolementation and add some notes about its limitations.
* bpo-31177: Skip deleted attributes while calling reset_mock (GH-9302)Xtreak2018-12-011-1/+1
|
* bpo-35133: Fix mistakes when concatenate string literals on different lines. ↵Serhiy Storchaka2018-11-051-1/+1
| | | | | | | | | | (GH-10284) Two kind of mistakes: 1. Missed space. After concatenating there is no space between words. 2. Missed comma. Causes unintentional concatenating in a list of strings.
* bpo-35047, unittest.mock: Better error messages on assert_called_xxx ↵Petter Strandmark2018-10-281-8/+28
| | | | | | | 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.
* bpo-35022: unittest.mock.MagicMock now also supports __fspath__ (GH-9960)Max Bélanger2018-10-251-0/+2
| | | | The MagicMock class supports many magic methods, but not __fspath__. To ease testing with modules such as os.path, this function is now supported by default.
* unittest.mock doc: Fix references to recursive seal of Mocks (GH-9028)Mario Corchero2018-10-191-5/+4
| | | | | The docs in `library/unittest.mock` have been updated to remove confusing terms about submock and be explicit about the behavior expected.
* bpo-32933: Implement __iter__ method on mock_open() (GH-5974)Tony Flury2018-09-121-3/+6
|
* Improve error message when mock.assert_has_calls fails (GH-8205)davidair2018-08-171-1/+3
| | | | | This makes the assertion error message more useful, aiding debugging. Thanks @davidair!
* pypi.python.org -> pypi.org (GH-7613)Ned Deily2018-06-111-1/+1
|
* bpo-33516: Add support for __round__ in MagicMock (GH-6880)John Reese2018-05-221-1/+1
| | | unittest.mock.MagicMock now supports the __round__() magic method.
* bpo-30541: Add new method to seal mocks (GH61923)Mario Corchero2017-10-171-2/+41
| | | | | | | The new method allows the developer to control when to stop the feature of mocks that automagically creates new mocks when accessing an attribute that was not declared before Signed-off-by: Mario Corchero <mariocj89@gmail.com>
* bpo-29403: Fix mock's broken autospec behavior on method-bound builtin ↵Aaron Gallagher2017-07-201-1/+1
| | | | | | | | | | | | | | | | | | | functions (GH-3) Cython will, in the right circumstances, offer a MethodType instance where im_func is a builtin function. Any instance of MethodType is automatically assumed to be a Python-defined function (more specifically, a function that has an inspectable signature), but _set_signature was still conservative in its assumptions. As a result _set_signature would return early with None instead of a mock since the im_func had no inspectable signature. This causes problems deeper inside mock, as _set_signature is assumed to _always_ return a mock, and nothing checked its return value. In similar corner cases, autospec will simply not check the spec of the function, so _set_signature is amended to now return early with the original, not-wrapped mock object. Patch by Aaron Gallagher.
* bpo-28911: Clarify the behaviour of assert_called_once_with. (#251)Arne de Laat2017-02-231-2/+2
|
* Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.Serhiy Storchaka2017-01-211-2/+6
|\
| * Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.Serhiy Storchaka2017-01-211-2/+6
| |\
| | * Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.Serhiy Storchaka2017-01-211-2/+6
| | |
* | | Issue #20804: The unittest.mock.sentinel attributes now preserve theirSerhiy Storchaka2017-01-111-0/+6
| | | | | | | | | | | | identity when they are copied or pickled.
* | | Merge 3.6Victor Stinner2017-01-061-2/+1
|\ \ \ | |/ /
| * | Fix unittest.mock._Call: don't ignore nameVictor Stinner2017-01-061-2/+1
| | | | | | | | | | | | | | | | | | | | | Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter anymore. Patch written by Jiajun Huang.
* | | Issue #28919: Simplify _copy_func_details() in unittest.mockBerker Peksag2016-12-151-18/+8
|/ / | | | | | | Patch by Jiajun Huang.
* | Fixes issue28380: unittest.mock Mock autospec functions now properly supportGregory P. Smith2016-10-061-0/+9
| | | | | | | | assert_called, assert_not_called, and assert_called_once.
* | Issue #26750: use inspect.isdatadescriptor instead of our ownGregory P. Smith2016-08-161-7/+1
|\ \ | |/ | | | | _is_data_descriptor().
| * Issue #26750: use inspect.isdatadescriptor instead of our ownGregory P. Smith2016-08-161-7/+1
| | | | | | | | _is_data_descriptor().
* | Issue #26750: unittest.mock.create_autospec() now works properly forGregory P. Smith2016-08-071-9/+5
|\ \ | |/ | | | | | | subclasses of property() and other data descriptors. Removes the never publicly used, never documented unittest.mock.DescriptorTypes tuple.
| * Issue #26750: unittest.mock.create_autospec() now works properlyGregory P. Smith2016-08-071-1/+9
| | | | | | | | for subclasses of property() and other data descriptors.
* | Issue #23804: Merge spelling and NEWS fixes from 3.5Martin Panter2016-07-111-1/+1
|\ \ | |/
| * English spelling and grammar fixesMartin Panter2016-07-111-1/+1
| |
* | Issue #23641: Added __getnewargs_ex__ to the list of special mock attributes.Serhiy Storchaka2016-06-191-0/+1
|\ \ | |/
| * Issue #23641: Added __getnewargs_ex__ to the list of special mock attributes.Serhiy Storchaka2016-06-191-0/+1
| |
* | Issue #21271: Adds new keyword only parameters in reset_mock callKushal Das2016-06-021-1/+6
| | | | | | | | | | We now have two keyword only parameters in the reset_mock function to selectively reset the return_value or the side_effects, or both.
* | Issue #26807: mock_open 'files' no longer error on readline at end of file.Robert Collins2016-05-161-0/+2
|\ \ | |/ | | | | Patch from Yolanda Robla.
| * Issue #26807: mock_open 'files' no longer error on readline at end of file.Robert Collins2016-05-161-0/+2
| | | | | | | | Patch from Yolanda Robla.
* | Issue #25195: Fix a regression in mock.MagicMockBerker Peksag2016-03-271-0/+3
|\ \ | |/ | | | | | | | | | | _Call is a subclass of tuple (changeset 3603bae63c13 only works for classes) so we need to implement __ne__ ourselves. Patch by Andrew Plummer.
| * Issue #25195: Fix a regression in mock.MagicMockBerker Peksag2016-03-271-0/+3
| | | | | | | | | | | | | | _Call is a subclass of tuple (changeset 3603bae63c13 only works for classes) so we need to implement __ne__ ourselves. Patch by Andrew Plummer.
* | Add Mock.assert_called()Victor Stinner2016-03-111-0/+18
| | | | | | | | | | Issue #26323: Add assert_called() and assert_called_once() methods to unittest.mock.Mock.