summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
Commit message (Collapse)AuthorAgeFilesLines
* bpo-39450 Stripped whitespace before parsing the docstring in ↵Steve Cirelli2020-02-032-1/+10
| | | | TestCase.shortDescription (GH-18175)
* Get mock coverage back to 100% (GH-18228)Chris Withers2020-01-294-54/+35
| | | | | | | | | | | | | | | | * use the `: pass` and `: yield` patterns for code that isn't expected to ever be executed. * The _Call items passed to _AnyComparer are only ever of length two, so assert instead of if/else * fix typo * Fix bug, where stop-without-start patching dict blows up with `TypeError: 'NoneType' object is not iterable`, highlighted by lack of coverage of an except branch. * The fix for bpo-37972 means _Call.count and _Call.index are no longer needed. * add coverage for calling next() on a mock_open with readline.return_value set. * __aiter__ is defined on the Mock so the one on _AsyncIterator is never called.
* bpo-39485: fix corner-case in method-detection of mock (GH-18252)Carl Friedrich Bolz-Tereick2020-01-291-5/+1
| | | | | | | | | | | | | | Replace check for whether something is a method in the mock module. The previous version fails on PyPy, because there no method wrappers exist (everything looks like a regular Python-defined function). Thus the isinstance(getattr(result, '__get__', None), MethodWrapperTypes) check returns True for any descriptor, not just methods. This condition could also return erroneously True in CPython for C-defined descriptors. Instead to decide whether something is a method, just check directly whether it's a function defined on the class. This passes all tests on CPython and fixes the bug on PyPy.
* Clarify and fix assertions that mocks have not been awaited (GH-18196)Chris Withers2020-01-272-27/+30
| | | | | - The gc.collect is needed for other implementations, such as pypy - Using context managers over multiple lines will only catch the warning from the first line in the context! - remove a skip for a test that no longer fails on pypy
* Use relative imports in mock and its tests to help backporting (GH-18197)Chris Withers2020-01-273-79/+82
| | | | | | | | * asyncio.run only available in 3.8+ * iscoroutinefunction has important bungfixes in 3.8 * IsolatedAsyncioTestCase only available in 3.8+
* bpo-25597: Ensure wraps' return value is used for magic methods in MagicMock ↵Karthikeyan Singaravelan2020-01-272-0/+53
| | | | (#16029)
* bpo-38932: Mock fully resets child objects on reset_mock(). (GH-17409)Vegard Stikbakke2020-01-252-2/+14
|
* bpo-37955: correct mock.patch docs with respect to the returned type (GH-15521)Paulo Henrique Silva2020-01-251-1/+2
|
* bpo-39082: Allow AsyncMock to correctly patch static/class methods (GH-18116)Matthew Kokotovich2020-01-252-0/+25
|
* bpo-38473: Handle autospecced functions and methods used with attach_mock ↵Karthikeyan Singaravelan2020-01-242-0/+33
| | | | (GH-16784)
* Fix `mock.patch.dict` to be stopped with `mock.patch.stopall` (#17606)Mario Corchero2020-01-242-2/+67
| | | | | As the function was not registering in the active patches, the mocks started by `mock.patch.dict` were not being stopped when `mock.patch.stopall` was being called.
* bpo-24928: Add test case for patch.dict using OrderedDict (GH -11437)Emmanuel Arias2020-01-241-0/+20
| | | | | * add test for path.dict using OrderedDict Co-authored-by: Yu Tomita nekobon@users.noreply.github.com
* Improve test coverage for AsyncMock. (GH-17906)Karthikeyan Singaravelan2020-01-151-4/+49
| | | | | * Add test for nested async decorator patch. * Add test for side_effect and wraps with a function. * Add test for side_effect with an exception in the iterable.
* remove unused __version__ from mock.py (#17977)Chris Withers2020-01-131-2/+0
| | | This isn't included in `__all__` and could be a source of confusion.
* bpo-38669: patch.object now raises a helpful error (GH17034)Elena Oat2019-12-082-0/+8
| | | This means a clearer message is now shown when patch.object is called with two string arguments, rather than a class and a string argument.
* bpo-38857: AsyncMock fix for awaitable values and StopIteration fix [3.8] ↵Jason Fried2019-11-212-41/+95
| | | | (GH-17269)
* Remove binding of captured exceptions when not used to reduce the chances of ↵Pablo Galindo2019-11-191-1/+1
| | | | | | | creating cycles (GH-17246) Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles. See for example GH-13135
* bpo-38839: Fix some unused functions in tests (GH-17189)Adam Johnson2019-11-191-0/+1
|
* bpo-38163: Child mocks detect their type as sync or async (GH-16471)Lisa Roach2019-09-302-27/+45
|
* bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443)Lisa Roach2019-09-302-39/+1
|
* bpo-38108: Makes mock objects inherit from Base (GH-16060)Lisa Roach2019-09-293-57/+56
|
* bpo-36871: Avoid duplicated 'Actual:' in assertion message (GH-16361)Samuel Freilich2019-09-243-18/+32
| | | | | 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-243-5/+61
| | | | | | | | | | | | 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-243-18/+191
|
* bpo-38093: Correctly returns AsyncMock for async subclasses. (GH-15947)Lisa Roach2019-09-203-55/+161
|
* bpo-37828: Fix default mock_name in unittest.mock.assert_called error (GH-16166)Abraham Toriz Cruz2019-09-172-1/+9
| | | | 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-38100: Fix spelling error in unittest.mock code (GH-16168)marcoramirezmx2019-09-161-3/+3
|
* bpo-38122: minor fixes to AsyncMock spec handling (GH-16099)Michael Foord2019-09-131-11/+8
|
* bpo-37555: Update _CallList.__contains__ to respect ANY (#14700)Elizabeth Uselton2019-09-133-13/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Flip equality to use mock calls' __eq__ * bpo-37555: Regression test demonstrating assert_has_calls not working with ANY and spec_set Co-authored-by: Neal Finne <neal@nealfinne.com> * Revert "Flip equality to use mock calls' __eq__" This reverts commit 94ddf54c5a8aab7d00d9ab93e1cc5695c28d73e7. * bpo-37555: Add regression tests for mock ANY ordering issues Add regression tests for whether __eq__ is order agnostic on _Call and _CallList, which is useful for comparisons involving ANY, especially if the ANY comparison is to a class not defaulting __eq__ to NotImplemented. Co-authored-by: Neal Finne <neal@nealfinne.com> * bpo-37555: Fix _CallList and _Call order sensitivity _Call and _CallList depend on ordering to correctly process that an object being compared to ANY with __eq__ should return True. This fix updates the comparison to check both a == b and b == a and return True if either condition is met, fixing situations from the tests in the previous two commits where assertEqual would not be commutative if checking _Call or _CallList objects. This seems like a reasonable fix considering that the Python data model specifies that if an object doesn't know how to compare itself to another object it should return NotImplemented, and that on getting NotImplemented from a == b, it should try b == a, implying that good behavior for __eq__ is commutative. This also flips the order of comparison in _CallList's __contains__ method, guaranteeing ANY will be on the left and have it's __eq__ called for equality checking, fixing the interaction between assert_has_calls and ANY. Co-author: Neal Finne <neal@neal.finne.com> * bpo-37555: Ensure _call_matcher returns _Call object * Adding ACK and news entry * bpo-37555: Replacing __eq__ with == to sidestep NotImplemented bool(NotImplemented) returns True, so it's necessary to use == instead of __eq__ in this comparison. * bpo-37555: cleaning up changes unnecessary to the final product * bpo-37555: Fixed call on bound arguments to respect args and kwargs * Revert "bpo-37555: Add regression tests for mock ANY ordering issues" This reverts commit 49c5310ad493c4356dd3bc58c03653cd9466c4fa. * Revert "bpo-37555: cleaning up changes unnecessary to the final product" This reverts commit 18e964ba0126d8964d89842cb95534b63c2d326e. * Revert "bpo-37555: Replacing __eq__ with == to sidestep NotImplemented" This reverts commit f295eaca5bceac6636c0e2b10e6c7d9a8ee8296a. * Revert "bpo-37555: Fix _CallList and _Call order sensitivity" This reverts commit 874fb697b8376fcea130116e56189061f944fde6. * Updated NEWS.d * bpo-37555: Add tests checking every function using _call_matcher both with and without spec * bpo-37555: Ensure all assert methods using _call_matcher are actually passing calls * Remove AnyCompare and use call objects everywhere. * Revert "Remove AnyCompare and use call objects everywhere." This reverts commit 24973c0b32ce7d796a7f4eeaf259832222aae0f5. * Check for exception in assert_any_await
* bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ ↵blhsing2019-09-112-0/+26
| | | | | | | | | | | | | | | | chaining so that call() can be subscriptable (GH-15565) * bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ chaining so that call() can be subscriptable * 📜🤖 Added by blurb_it. * Update 2019-08-28-21-40-12.bpo-37972.kP-n4L.rst added name of the contributor * bpo-37972: made all dunder methods chainable for _Call * bpo-37972: delegate only attributes of tuple instead to __getattr__
* bpo-36373: Fix deprecation warnings (GH-15889)Andrew Svetlov2019-09-111-4/+6
| | | https://bugs.python.org/issue36373
* bpo-37251: Removes __code__ check from _is_async_obj. (GH-15830)Lisa Roach2019-09-102-3/+17
|
* docs: Add references to AsyncMock in unittest.mock.patch (#13681)Mario Corchero2019-09-091-4/+5
| | | | Update the docs as patch can now return an AsyncMock if the patched object is an async function.
* bpo-34596: Fallback to a default reason when @unittest.skip is uncalled (#9082)Naitree Zhu2019-09-092-0/+16
| | | | | | | | * bpo-34596: Fallback to a default reason when @unittest.skip is uncalled * Change default reason to empty string * Fix rst formatting of NEWS entry
* bpo-37212: Preserve keyword argument order in unittest.mock.call and error ↵Xtreak2019-09-092-4/+4
| | | | messages (GH-14310)
* Fix assertions regarding magic methods function body that was not executed ↵Xtreak2019-09-091-9/+2
| | | | (GH-14154)
* Fix typos mostly in comments, docs and test names (GH-15209)Min ho Kim2019-08-301-3/+3
|
* bpo-36743: __get__ is sometimes called without the owner argument (#12992)Raymond Hettinger2019-08-291-1/+1
|
* bpo-35946: Improve assert_called_with documentation (GH-11796)Rémi Lapeyre2019-08-291-1/+1
|
* bpo-36871: Ensure method signature is used when asserting mock calls to a ↵Xtreak2019-08-292-1/+83
| | | | | | | | | | | | | | | | 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-9949: Enable symlink traversal for ntpath.realpath (GH-15287)Steve Dower2019-08-211-0/+6
|
* bpo-37685: Fixed __eq__, __lt__ etc implementations in some classes. (GH-14952)Serhiy Storchaka2019-08-082-3/+9
| | | | They now return NotImplemented for unsupported type of the other operand.
* Fix typos in comments, docs and test names (#15018)Min ho Kim2019-07-302-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | * 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-222-11/+53
| | | | | | | | | | | | | | 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.
* [3.9] bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-12620)Serhiy Storchaka2019-06-052-21/+3
| | | Turn deprecation warnings added in 3.8 into TypeError.
* bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700)Serhiy Storchaka2019-06-013-78/+39
|
* bpo-32972: Async test case (GH-13386)Andrew Svetlov2019-05-294-5/+371
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add explicit `asyncSetUp` and `asyncTearDown` methods. The rest is the same as for #13228 `AsyncTestCase` create a loop instance for every test for the sake of test isolation. Sometimes a loop shared between all tests can speed up tests execution time a lot but it requires control of closed resources after every test finish. Basically, it requires nested supervisors support that was discussed with @1st1 many times. Sorry, asyncio supervisors have no chance to land on Python 3.8. The PR intentionally does not provide API for changing the used event loop or getting the test loop: use `asyncio.set_event_loop_policy()` and `asyncio.get_event_loop()` instead. The PR adds four overridable methods to base `unittest.TestCase` class: ``` def _callSetUp(self): self.setUp() def _callTestMethod(self, method): method() def _callTearDown(self): self.tearDown() def _callCleanup(self, function, /, *args, **kwargs): function(*args, **kwargs) ``` It allows using asyncio facilities with minimal influence on the unittest code. The last but not least: the PR respects contextvars. The context variable installed by `asyncSetUp` is available on test, `tearDown` and a coroutine scheduled by `addCleanup`. https://bugs.python.org/issue32972
* bpo-37075: Fix string concatenation in assert_has_awaits error message ↵Xtreak2019-05-292-7/+9
| | | | | | | | | | (GH-13616) * Fix the implicit string concatenation in `assert_has_awaits` error message. * Use "await" instead of "call" in `assert_awaited_with` error message. https://bugs.python.org/issue37075
* bpo-32299: Return patched dict when using patch.dict as a context manager ↵Mario Corchero2019-05-282-0/+8
| | | | | | (GH-11062)
* bpo-36996: Handle async functions when mock.patch is used as a decorator ↵Xtreak2019-05-282-27/+73
| | | | | | | | | | (GH-13562) Return a coroutine while patching async functions with a decorator. Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com> https://bugs.python.org/issue36996