summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/testmock/testmock.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-36871: Avoid duplicated 'Actual:' in assertion message (GH-16361)Samuel Freilich2019-09-241-7/+14
| | | | | Fixes an issue caught after merge of PR 16005. Tightened test assertions to check the entire assertion message.
* bpo-36871: Handle spec errors in assert_has_calls (GH-16005)Samuel Freilich2019-09-241-0/+19
| | | | | | | | | | | | The fix in PR 13261 handled the underlying issue about the spec for specific methods not being applied correctly, but it didn't fix the issue that was causing the misleading error message. The code currently grabs a list of responses from _call_matcher (which may include exceptions). But it doesn't reach inside the list when checking if the result is an exception. This results in a misleading error message when one of the provided calls does not match the spec. https://bugs.python.org/issue36871 Automerge-Triggered-By: @gpshead
* bpo-38136: Updates await_count and call_count to be different things (GH-16192)Lisa Roach2019-09-241-1/+2
|
* bpo-37828: Fix default mock_name in unittest.mock.assert_called error (GH-16166)Abraham Toriz Cruz2019-09-171-0/+8
| | | | In the format string for assert_called the evaluation order is incorrect and hence for mock's without name, 'None' is printed whereas it should be 'mock' like for other messages. The error message is ("Expected '%s' to have been called." % self._mock_name or 'mock').
* bpo-37212: Preserve keyword argument order in unittest.mock.call and error ↵Xtreak2019-09-091-3/+3
| | | | messages (GH-14310)
* bpo-36871: Ensure method signature is used when asserting mock calls to a ↵Xtreak2019-08-291-0/+48
| | | | | | | | | | | | | | | | method (GH13261) * Fix call_matcher for mock when using methods * Add NEWS entry * Use None check and convert doctest to unittest * Use better name for mock in tests. Handle _SpecState when the attribute was not accessed and add tests. * Use reset_mock instead of reinitialization. Change inner class constructor signature for check * Reword comment regarding call object lookup logic
* bpo-37685: Fixed __eq__, __lt__ etc implementations in some classes. (GH-14952)Serhiy Storchaka2019-08-081-0/+8
| | | | They now return NotImplemented for unsupported type of the other operand.
* Fix typos in comments, docs and test names (#15018)Min ho Kim2019-07-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * Fix typos in comments, docs and test names * Update test_pyparse.py account for change in string length * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: splitable -> splittable Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Apply suggestion: Dealloccte -> Deallocate Co-Authored-By: Terry Jan Reedy <tjreedy@udel.edu> * Update posixmodule checksum. * Reverse idlelib changes.
* bpo-21478: Record calls to parent when autospecced objects are used as child ↵Xtreak2019-07-221-0/+37
| | | | | | | | | | | | | | with attach_mock (GH 14688) * Clear name and parent of mock in autospecced objects used with attach_mock * Add NEWS entry * Fix reversed order of comparison * Test child and standalone function calls * Use a helper function extracting mock to avoid code duplication and refactor tests.
* bpo-37008: make mock_open handle able to honor next() (GH-13492)Damien Nadé2019-05-231-0/+13
| | | | | | | | I've reported the issue on https://bugs.python.org/issue37008 and now I'm trying to bring a solution to this minor issue. I think it could be trivially backported to 3.7 branch. https://bugs.python.org/issue37008
* bpo-26467: Adds AsyncMock for asyncio Mock library support (GH-9296)Lisa Roach2019-05-201-2/+3
|
* bpo-24758: Improve the error msg for unittest.mock.Mock()'s unsafe mode (#12991)Zackery Spytz2019-05-081-2/+3
| | | | | | * bpo-24758: Improve the error msg for unittest.mock.Mock()'s unsafe mode * Make the requested changes.
* Mock 100% coverage (GH-13045)Chris Withers2019-05-011-53/+73
| | | | | | | | | | | 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-15/+0
|
* Don't report deleted attributes in __dir__ (GH#10148)Mario Corchero2019-04-301-0/+9
| | | | | | 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-0/+17
| | | | | (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-0/+38
| | | | | 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-21269: Provide args and kwargs attributes on mock call objects GH11807Kumar Akshay2019-03-221-3/+8
|
* Autospec functions should propagate mock calls to parent GH-11273Xtreak2019-02-251-0/+13
|
* bpo-35500: align expected and actual calls on mock.assert_called_with error ↵Susan Su2019-02-141-7/+8
| | | | message. (GH-11804)
* bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)Pablo Galindo2019-01-211-0/+27
| | | | | | | | * 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
* bpo-35330: Don't call the wrapped object if `side_effect` is set (GH10973)Mario Corchero2018-12-081-0/+122
| | | | | | | | | | | | | | | | | | | | | | | * 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-1/+15
| | | | | _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-0/+51
| | | | 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-0/+10
|
* bpo-35047, unittest.mock: Better error messages on assert_called_xxx ↵Petter Strandmark2018-10-281-0/+30
| | | | | | | 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-32933: Implement __iter__ method on mock_open() (GH-5974)Tony Flury2018-09-121-0/+10
|
* Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.Serhiy Storchaka2017-01-211-3/+14
|\
| * Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.Serhiy Storchaka2017-01-211-3/+14
| |
* | Issue #21271: Adds new keyword only parameters in reset_mock callKushal Das2016-06-021-0/+18
| | | | | | | | | | 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/+12
|\ \ | |/ | | | | Patch from Yolanda Robla.
| * Issue #26807: mock_open 'files' no longer error on readline at end of file.Robert Collins2016-05-161-0/+12
| | | | | | | | Patch from Yolanda Robla.
* | Issue #25195: Fix a regression in mock.MagicMockBerker Peksag2016-03-271-0/+17
|\ \ | |/ | | | | | | | | | | _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/+17
| | | | | | | | | | | | | | _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/+21
|/ | | | | Issue #26323: Add assert_called() and assert_called_once() methods to unittest.mock.Mock.
* Issue #24857: Comparing call_args to a long sequence now correctly returns aBerker Peksag2015-09-091-0/+3
|\ | | | | | | | | | | boolean result instead of raising an exception. Patch by A Kaptur.
| * Issue #24857: Comparing call_args to a long sequence now correctly returns aBerker Peksag2015-09-091-0/+3
| | | | | | | | | | | | boolean result instead of raising an exception. Patch by A Kaptur.
* | Issue #21750: Further fixup to be styled like other mock APIs.Robert Collins2015-07-231-1/+23
|\ \ | |/
| * Issue #21750: Further fixup to be styled like other mock APIs.Robert Collins2015-07-231-1/+23
| |
* | Issue #21750: mock_open.read_data can now be read from each instance, as itRobert Collins2015-07-171-0/+5
|\ \ | |/ | | | | could in Python 3.3.
| * Issue #21750: mock_open.read_data can now be read from each instance, as itRobert Collins2015-07-171-0/+5
| | | | | | | | could in Python 3.3.
* | - Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.Robert Collins2015-07-141-0/+3
|\ \ | |/ | | | | Patch from Nicola Palumbo and Laurent De Buyst.
| * - Issue #18622: unittest.mock.mock_open().reset_mock would recurse infinitely.Robert Collins2015-07-141-0/+3
| | | | | | | | Patch from Nicola Palumbo and Laurent De Buyst.
* | Issue #23661: unittest.mock side_effects can now be exceptions again.Robert Collins2015-07-141-0/+9
| | | | | | | | This was a regression vs Python 3.4. Patch from Ignacio Rossi
* | Closes #21270 : We now override tuple methods in mock.call objects.Kushal Das2014-09-161-0/+10
| |
* | Suppress a couple more DeprecationWarnings in the test suite.R David Murray2014-06-111-1/+1
| |
* | Closes #21256: Printout of keyword args in deterministic order in mock calls.Kushal Das2014-06-091-0/+6
| | | | | | | | | | Printout of keyword args should be in deterministic order in a mock function call. This will help to write better doctests.
* | Closes Issue 21262: New method assert_not_called for Mock.Kushal Das2014-04-161-0/+9
| | | | | | | | It raises AssertionError if the mock has been called.
* | Closes Issue 21238: New keyword argument `unsafe` to Mock.Kushal Das2014-04-161-0/+11
|/ | | | | It raises `AttributeError` incase of an attribute startswith assert or assret.
* Closes Issue 21222.Kushal Das2014-04-151-0/+4
| | | | Passing name keyword argument to mock.create_autospec now works.