summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
Commit message (Collapse)AuthorAgeFilesLines
* bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)Miss Islington (bot)2020-12-162-2/+29
| | | | | (cherry picked from commit 8374d2ee1589791be8892b00f4bbf8121dde24bd) Co-authored-by: Lisa Roach <lisaroach14@gmail.com>
* bpo-29620: iterate over a copy of sys.modules (GH-4800) (GH-20816)Miss Islington (bot)2020-06-112-1/+16
| | | | | | | | unittest.TestCase.assertWarns no longer raises a RuntimeException when accessing a module's ``__warningregistry__`` causes importation of a new module, or when a new module is imported in another thread. (cherry picked from commit 46398fba4d66ad342cf2504ef947b5fb857423b2) Co-authored-by: kernc <kerncece@gmail.com>
* [3.8] bpo-40126: Fix reverting multiple patches in unittest.mock. (GH-19351) ↵Serhiy Storchaka2020-04-121-46/+24
| | | | | | | | | (GH-19483) Patcher's __exit__() is now never called if its __enter__() is failed. Returning true from __exit__() silences now the exception. (cherry picked from commit 4b222c9491d1700e9bdd98e6889b8d0ea1c7321e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-39915: Ensure await_args_list is updated according to the order in which ↵Miss Islington (bot)2020-03-142-1/+12
| | | | | | | | coroutines were awaited (GH-18927) Create call objects with awaited arguments instead of using call_args which has only last call value. (cherry picked from commit e553f204bf0e39b1d701a364bc71b286acb9433f) Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
* bpo-39450 Stripped whitespace before parsing the docstring in ↵Miss Islington (bot)2020-02-032-1/+10
| | | | | | | TestCase.shortDescription (GH-18175) (#18323) (cherry picked from commit 032de7324e30c6b44ef272cea3be205a3d768759) Co-authored-by: Steve Cirelli <scirelli+git@gmail.com>
* bpo-39485: fix corner-case in method-detection of mock (GH-18255)Miss Islington (bot)2020-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. (cherry picked from commit a327677905956ae0b239ff430a1346dfe265709e) Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de> Co-authored-by: Carl Friedrich Bolz-Tereick <cfbolz@gmx.de>
* [3.8] bpo-39082: Allow AsyncMock to correctly patch static/class methods ↵Matthew Kokotovich2020-01-262-0/+25
| | | | | | | (GH-18190) (cherry picked from commit 62865f4532094017a9b780b704686ca9734bc329) Co-authored-by: Matthew Kokotovich <mkokotovich@gmail.com>
* bpo-38473: Handle autospecced functions and methods used with attach_mock ↵Miss Islington (bot)2020-01-252-0/+33
| | | | | | | | | | | (GH-16784) (GH-18167) If an autospecced object is attached using attach_mock the child would be a function with mock object as attribute from which signature has to be derived. (cherry picked from commit 66b00a9d3aacf6ed49412f48743e4913104a2bb3) Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
* Improve test coverage for AsyncMock. (GH-17906)Miss Islington (bot)2020-01-241-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. (cherry picked from commit 54f743eb315f00b0ff45e115dde7a5d506034153) Co-authored-by: Karthikeyan Singaravelan <tir.karthi@gmail.com>
* bpo-38669: patch.object now raises a helpful error (GH17510)Miss Islington (bot)2019-12-092-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. (cherry picked from commit cd90a52983db34896a6335a572d55bdda274778f) Co-authored-by: Elena Oat <oat.elena@gmail.com>
* [3.8] bpo-38857: AsyncMock fix for awaitable values and StopIteration fix ↵Lisa Roach2019-11-212-41/+95
| | | | | | | [3.8] (GH-17269) (#17304) (cherry picked from commit 046442d02bcc6e848e71e93e47f6cde9e279e993) Co-authored-by: Jason Fried <fried@fb.com>
* [3.8] bpo-38163: Child mocks detect their type as sync or async (GH-16471) ↵Lisa Roach2019-09-302-27/+45
| | | | (GH-16484)
* bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443) (GH-16481)Miss Islington (bot)2019-09-302-39/+1
|
* bpo-38108: Makes mock objects inherit from Base (GH-16060) (GH-16470)Miss Islington (bot)2019-09-303-57/+56
|
* [3.8] bpo-38136: Updates await_count and call_count to be different things ↵Lisa Roach2019-09-273-19/+192
| | | | (GH-16192) (GH-16431)
* [3.8] bpo-36871: Handle spec errors in assert_has_calls (GH-16005) (GH-16364)Miss Islington (bot)2019-09-253-5/+75
| | | | | | | | | | | | | | | | | | | | | | | 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 (cherry picked from commit b5a7a4f0c20717a4c92c371583b5521b83f40f32) Co-authored-by: Samuel Freilich <sfreilich@google.com> https://bugs.python.org/issue36871 Automerge-Triggered-By: @gpshead
* [3.8] bpo-38093: Correctly returns AsyncMock for async subclasses. ↵Lisa Roach2019-09-213-63/+161
| | | | | | | | (GH-15947) (GH-16299) (cherry picked from commit 8b03f943c37e07fb2394acdcfacd066647f9b1fd) Co-authored-by: Lisa Roach <lisaroach14@gmail.com>
* bpo-37828: Fix default mock_name in unittest.mock.assert_called error (GH-16166)Miss Islington (bot)2019-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'). (cherry picked from commit 5f5f11faf9de0d8dcbe1a8a4eb35d2a4232d6eaa) Co-authored-by: Abraham Toriz Cruz <awonderfulcode@gmail.com>
* bpo-38100: Fix spelling error in unittest.mock code (GH-16168)Miss Islington (bot)2019-09-161-3/+3
| | | | | (cherry picked from commit a9187c31185fe7ea47271839898416400cc3d976) Co-authored-by: marcoramirezmx <55331462+marcoramirezmx@users.noreply.github.com>
* bpo-37972: unittest.mock._Call now passes on __getitem__ to the __getattr__ ↵Miss Islington (bot)2019-09-122-0/+26
| | | | | | | | | | | | | | | | | | chaining so that call() can be subscriptable (GH-15565) (GH-15965) * 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__ (cherry picked from commit 72c359912d36705a94fca8b63d80451905a14ae4) Co-authored-by: blhsing <github@ydooby.com>
* [3.8] bpo-36373: Fix deprecation warnings (GH-15889) (GH-15901)Andrew Svetlov2019-09-111-4/+6
| | | | | | https://bugs.python.org/issue36373 (cherry picked from commit 7264e92b718d307cc499b2f10eab7644b00f0499) Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
* bpo-37251: Removes __code__ check from _is_async_obj. (GH-15830)Miss Islington (bot)2019-09-102-3/+17
| | | | | (cherry picked from commit f1a297acb60b88917712450ebd3cfa707e6efd6b) Co-authored-by: Lisa Roach <lisaroach14@gmail.com>
* docs: Add references to AsyncMock in unittest.mock.patch (GH-13681)Miss Islington (bot)2019-09-101-4/+5
| | | | | | | Update the docs as patch can now return an AsyncMock if the patched object is an async function. (cherry picked from commit f5e7f39d2916ed150e80381faed125f405a11e11) Co-authored-by: Mario Corchero <mcorcherojim@bloomberg.net>
* bpo-34596: Fallback to a default reason when @unittest.skip is uncalled ↵Miss Islington (bot)2019-09-092-0/+16
| | | | | | | | | | | | (GH-9082) (#15781) * bpo-34596: Fallback to a default reason when @unittest.skip is uncalled * Change default reason to empty string * Fix rst formatting of NEWS entry (cherry picked from commit d5fd75c53fad7049fc640c9a6162d35f0c5bea03) Co-authored-by: Naitree Zhu <Naitreey@gmail.com>
* bpo-37212: Preserve keyword argument order in unittest.mock.call and error ↵Miss Islington (bot)2019-09-092-4/+4
| | | | | | | messages (GH-14310) (cherry picked from commit 9d607061c9c888913ae2c18543775cf360d55f27) Co-authored-by: Xtreak <tir.karthi@gmail.com>
* Fix typos mostly in comments, docs and test names (GH-15209)Miss Islington (bot)2019-08-301-3/+3
| | | | | (cherry picked from commit 39d87b54715197ca9dcb6902bb43461c0ed701a2) Co-authored-by: Min ho Kim <minho42@gmail.com>
* bpo-36743: __get__ is sometimes called without the owner argument (GH-12992) ↵Miss Islington (bot)2019-08-291-1/+1
| | | | | | | (GH-15589) (cherry picked from commit 0dac68f1e593c11612ed54af9edb865d398f3b05) Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
* bpo-36871: Ensure method signature is used when asserting mock calls to a ↵Miss Islington (bot)2019-08-292-1/+83
| | | | | | | | | | | | | | | | | | method (GH15578) * 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 (cherry picked from commit c96127821ebda50760e788b1213975a0d5bea37f) Co-authored-by: Xtreak <tir.karthi@gmail.com>
* bpo-35946: Improve assert_called_with documentation (GH-11796)Miss Islington (bot)2019-08-291-1/+1
| | | | | (cherry picked from commit f5896a05edf5df91fb1b55bd481ba5b2a3682f4e) Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
* bpo-9949: Enable symlink traversal for ntpath.realpath (GH-15287)Miss Islington (bot)2019-08-211-0/+6
| | | | | (cherry picked from commit 75e064962ee0e31ec19a8081e9d9cc957baf6415) Co-authored-by: Steve Dower <steve.dower@python.org>
* bpo-21478: Record calls to parent when autospecced objects are used as child ↵Miss Islington (bot)2019-07-222-11/+53
| | | | | | | | | | | | | | | | with attach_mock (GH 14688) (GH-14902) * 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. (cherry picked from commit 7397cda99795a4a8d96193d710105e77a07b7411) Co-authored-by: Xtreak <tir.karthi@gmail.com>
* 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
* bpo-37047: Refactor AsyncMock setup logic for autospeccing (GH-13574)Xtreak2019-05-272-23/+99
| | | | Handle late binding and attribute access in unittest.mock.AsyncMock setup for autospeccing.
* bpo-37008: make mock_open handle able to honor next() (GH-13492)Damien Nadé2019-05-233-0/+34
| | | | | | | | 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
* Fix RuntimeWarning in unittest.mock asyncio example (GH-13449)Xtreak2019-05-211-1/+1
| | | | * This PR fixes the `RuntimeWarning` in `inspect.isawaitable(mock())` where `mock()` was not awaited. * Fix typo in asynctest project.
* bpo-26467: Adds AsyncMock for asyncio Mock library support (GH-9296)Lisa Roach2019-05-203-19/+941
|
* Fix typo in test comment (GH-11442)Ashwin Ramaswami2019-05-191-1/+1
|
* bpo-24758: Improve the error msg for unittest.mock.Mock()'s unsafe mode (#12991)Zackery Spytz2019-05-082-3/+5
| | | | | | * bpo-24758: Improve the error msg for unittest.mock.Mock()'s unsafe mode * Make the requested changes.
* bpo-31855: unittest.mock.mock_open() results now respects the argument of ↵Rémi Lapeyre2019-05-072-26/+20
| | | | | | | | read([size]) (GH-11521) unittest.mock.mock_open() results now respects the argument of read([size]) Co-Authored-By: remilapeyre <remi.lapeyre@henki.fr>
* bpo-36542: Allow to overwrite the signature for Python functions. (GH-12705)Serhiy Storchaka2019-05-061-1/+4
|
* Mock 100% coverage (GH-13045)Chris Withers2019-05-019-317/+263
| | | | | | | | | | | 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-013-25/+2
|
* Don't report deleted attributes in __dir__ (GH#10148)Mario Corchero2019-04-302-2/+13
| | | | | | 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-36751: Deprecate getfullargspec and report positional-only args as ↵Pablo Galindo2019-04-301-2/+2
| | | | | | | | regular args (GH-13016) * bpo-36751: Deprecate getfullargspec and report positional-only args as regular args * Use inspect.signature in testhelpers
* Document that TestCase.assertCountEqual() can take iterables (GH-686)jkleint2019-04-231-3/+2
|
* bpo-23078: Add support for {class,static}method to mock.create_autospec() ↵Xtreak2019-04-224-2/+79
| | | | | (GH-11613) Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>