summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
Commit message (Collapse)AuthorAgeFilesLines
* bpo-45102: unittest: add tests for skipping and errors in cleanup (GH-28166)Miss Islington (bot)2021-09-051-0/+138
| | | | | (cherry picked from commit 28264269de9ff88d9ee7110fc56ac2d2db275bec) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-43913: Fix bugs in cleaning up classes and modules in unittest. (GH-28006)Miss Islington (bot)2021-08-303-70/+711
| | | | | | | | | | | | | | | | | * Functions registered with addModuleCleanup() were not called unless the user defines tearDownModule() in their test module. * Functions registered with addClassCleanup() were not called if tearDownClass is set to None. * Buffering in TestResult did not work with functions registered with addClassCleanup() and addModuleCleanup(). * Errors in functions registered with addClassCleanup() and addModuleCleanup() were not handled correctly in buffered and debug modes. * Errors in setUpModule() and functions registered with addModuleCleanup() were reported in wrong order. * And several lesser bugs. (cherry picked from commit 08d9e597c8ef5a2b26375ac954fdf224f5d82c3c) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-41620: TestCase.run() now always return a TestResult instance (GH-28030)Miss Islington (bot)2021-08-302-24/+31
| | | | | | | | | Previously it returned None if the test class or method was decorated with a skipping decorator. Co-authored-by: Iman Tabrizian <iman.tabrizian@gmail.com> (cherry picked from commit 7e246a3a7b43762480ee4fe0cfb859e8e997a8c8) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44955: Always call stopTestRun() for implicitly created TestResult ↵Miss Islington (bot)2021-08-222-53/+99
| | | | | | | | | | | objects (GH-27831) Method stopTestRun() is now always called in pair with method startTestRun() for TestResult objects implicitly created in TestCase.run(). Previously it was not called for test methods and classes decorated with a skipping decorator. (cherry picked from commit a9640d75531d6cbbfd254b65435f238c26bf5cd9) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44911: Fixed IsolatedAsyncioTestCase from throwing an exception on ↵Miss Islington (bot)2021-08-162-1/+21
| | | | | | | leaked tasks (GH-27765) (cherry picked from commit 2cb1a6806c0cefab0c3a40fdd428a89a4392570e) Co-authored-by: Bar Harel <bar.harel@biocatch.com>
* bpo-43478: Restrict use of Mock objects as specs (GH-25326)Matthew Suozzo2021-04-103-8/+64
| | | | * Restrict using Mock objects as specs as this is always a test bug where the resulting mock is misleadingly useless. * Skip a broken test that exposes a bug elsewhere in mock (noted in the original issue).
* bpo-42934: use TracebackException(compact=True) in unittest.TestResult ↵Irit Katriel2021-01-151-1/+2
| | | | (GH-24221)
* bpo-41877: Check for misspelled speccing arguments (GH-23737)vabr-g2020-12-142-8/+83
| | | | | | | | | | | | patch, patch.object and create_autospec silently ignore misspelled arguments such as autospect, auto_spec and set_spec. This can lead to tests failing to check what they are supposed to check. This change adds a check causing a RuntimeError if the above functions get any of the above misspellings as arguments. It also adds a new argument, "unsafe", which can be set to True to disable this check. Also add "!r" to format specifiers in added error messages.
* bpo-41877: Improve docs for assert misspellings check in mock (GH-23729)vabr-g2020-12-102-3/+4
| | | | | | | | | This is a follow-up to https://github.com/python/cpython/commit/4662fa9bfe4a849fe87bfb321d8ef0956c89a772. That original commit expanded guards against misspelling assertions on mocks. This follow-up updates the documentation and improves the error message by pointing out the potential cause and solution. Automerge-Triggered-By: GH:gpshead
* bpo-42532: Check if NonCallableMock's spec_arg is not None instead of call ↵idanw2062020-12-062-1/+11
| | | | | | its __bool__ function (GH23613) Check if NonCallableMock's spec_arg is not None instead of call its __bool__ function
* bpo-41877 Check for asert, aseert, assrt in mocks (GH-23165)vabr-g2020-11-052-3/+12
| | | | | | | | | | | Currently, a Mock object which is not unsafe will raise an AttributeError if an attribute with the prefix assert or assret is accessed on it. This protects against misspellings of real assert method calls, which lead to tests passing silently even if the tested code does not satisfy the intended assertion. Recently a check was done in a large code base (Google) and three more frequent ways of misspelling assert were found causing harm: asert, aseert, assrt. These are now added to the existing check.
* bpo-41943: Fix bug where assertLogs doesn't correctly filter messages… ↵Irit Katriel2020-11-022-0/+13
| | | | | | | | | (GH-22565) … by level @vsajip , @pitrou Automerge-Triggered-By: GH:vsajip
* bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654)Lisa Roach2020-10-262-2/+29
|
* bpo-40275: Use new test.support helper submodules in tests (GH-21449)Hai Shi2020-08-032-5/+6
|
* bpo-39385: Add an assertNoLogs context manager to unittest.TestCase (GH-18067)Kit Choi2020-07-013-8/+107
| | | Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
* bpo-29620: iterate over a copy of sys.modules (GH-4800)kernc2020-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. Patch by Kernc.
* bpo-40462: fix variable and function names (GH-19832)Furkan Önder2020-05-011-2/+0
| | | Automerge-Triggered-By: @vstinner
* bpo-39966: Revert "bpo-25597: Ensure wraps' return value is used for magic ↵Karthikeyan Singaravelan2020-04-282-12/+10
| | | | | | | methods in MagicMock" (GH-19734) * Revert "bpo-25597: Ensure wraps' return value is used for magic methods in MagicMock (#16029)" This reverts commit 72b1004657e60c900e4cd031b2635b587f4b280e.
* bpo-40275: Avoid importing logging in test.support (GH-19601)Serhiy Storchaka2020-04-252-68/+71
| | | | | Import logging lazily in assertLogs() in unittest. Move TestHandler from test.support to logging_helper.
* bpo-40275: Avoid importing asyncio in test.support (GH-19600)Serhiy Storchaka2020-04-251-1/+16
| | | | | * Import asyncio lazily in unittest (only when IsolatedAsyncioTestCase is used). * Import asyncio.events lazily in test.support.
* bpo-40126: Fix reverting multiple patches in unittest.mock. (GH-19351)Serhiy Storchaka2020-04-112-49/+27
| | | | | Patcher's __exit__() is now never called if its __enter__() is failed. Returning true from __exit__() silences now the exception.
* bpo-39481: PEP 585 for a variety of modules (GH-19423)Batuhan Taşkaya2020-04-101-0/+2
| | | | | | | | | | - concurrent.futures - ctypes - http.cookies - multiprocessing - queue - tempfile - unittest.case - urllib.parse
* bpo-39915: Ensure await_args_list is updated according to the order in which ↵Karthikeyan Singaravelan2020-03-112-1/+12
| | | | | coroutines were awaited (GH-18924) Create call objects with awaited arguments instead of using call_args which has only last call value.
* 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
|