summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
Commit message (Collapse)AuthorAgeFilesLines
* 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
* 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>
* bpo-36593: Fix isinstance check for Mock objects with spec executed under ↵Xtreak2019-04-132-1/+39
| | | | | 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-36492: Deprecate passing some arguments as keyword arguments. (GH-12637)Serhiy Storchaka2019-04-012-3/+101
| | | | | | | | | | | | | | | | | | | | | | Deprecated passing the following arguments as keyword arguments: - "func" in functools.partialmethod(), weakref.finalize(), profile.Profile.runcall(), cProfile.Profile.runcall(), bdb.Bdb.runcall(), trace.Trace.runfunc() and curses.wrapper(). - "function" in unittest.addModuleCleanup() and unittest.TestCase.addCleanup(). - "fn" in the submit() method of concurrent.futures.ThreadPoolExecutor and concurrent.futures.ProcessPoolExecutor. - "callback" in contextlib.ExitStack.callback(), contextlib.AsyncExitStack.callback() and contextlib.AsyncExitStack.push_async_callback(). - "c" and "typeid" in the create() method of multiprocessing.managers.Server and multiprocessing.managers.SharedMemoryServer. - "obj" in weakref.finalize(). Also allowed to pass arbitrary keyword arguments (even "self" and "func") if the above arguments are passed as positional argument.
* bpo-36366: Return None on stopping unstarted patch object (GH-12472)Xtreak2019-03-282-3/+11
| | | | | | 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-223-3/+33
|
* Autospec functions should propagate mock calls to parent GH-11273Xtreak2019-02-252-0/+21
|
* bpo-35512: Resolve string target to patch.dict decorator during function ↵Xtreak2019-02-243-2/+22
| | | | | | | | | | | | | | 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-142-9/+13
| | | | message. (GH-11804)
* bpo-35767: Fix unittest.loader to allow partials as test_functions (#11600)Jason Fried2019-01-232-1/+19
|
* bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)Pablo Galindo2019-01-212-4/+30
| | | | | | | | * 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-35513, unittest: TextTestRunner uses time.perf_counter() (GH-11180)Victor Stinner2018-12-171-2/+2
| | | | | | | TextTestRunner of unittest.runner now uses time.perf_counter() rather than time.time() to measure the execution time of a test: time.time() can go backwards, whereas time.perf_counter() is monotonic. Similar change made in libregrtest, pprint and random.
* Add test for double patching instance methods (#11085)Anthony Sottile2018-12-121-0/+14
|
* bpo-17185: Add __signature__ to mock that can be used by inspect for ↵Xtreak2018-12-122-2/+34
| | | | | | | | | | | | | | | | 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-082-11/+132
| | | | | | | | | | | | | | | | | | | | | | | * 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-33747: Avoid mutating the global sys.modules dict in unittest.mock tests ↵Anirudha Bose2018-12-071-11/+16
| | | | (GH-8520)
* Remove unused function in `testmock/support.py` (GH-10975)Mario Corchero2018-12-061-7/+0
| | | | The function is never imported and the implementation is actually buggy. As `warnings.catch_warnings` is not imported here.
* bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of ↵Andrew Dunai2018-12-043-16/+30
| | | | | _Call/_MagicProxy. (#10873) Fix minor typo in test function name.
* bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)Chris Withers2018-12-033-23/+99
| | | | Also refactor the call recording imolementation and add some notes about its limitations.