summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
Commit message (Collapse)AuthorAgeFilesLines
* bpo-39450 Stripped whitespace before parsing the docstring in ↵Miss Islington (bot)2020-02-031-0/+9
| | | | | | | TestCase.shortDescription (GH-18321) (cherry picked from commit 032de7324e30c6b44ef272cea3be205a3d768759) Co-authored-by: Steve Cirelli <scirelli+git@gmail.com>
* bpo-38473: Handle autospecced functions and methods used with attach_mock ↵Miss Islington (bot)2020-01-251-0/+29
| | | | | | | | | | | | (GH-16784) (#18166) 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>
* bpo-38669: patch.object now raises a helpful error (GH17511)Miss Islington (bot)2019-12-091-0/+4
| | | | | | 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.7] bpo-36871: Handle spec errors in assert_has_calls (GH-16364) (GH-16374)Gregory P. Smith2019-09-251-0/+27
| | | | | | | | | | | | | Handle spec errors in assert_has_calls (GH-16005) (GH-16364) 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 Co-authored-by: Samuel Freilich <sfreilich@google.com> (cherry picked from commit 1a17a054f6314ce29cd2632c28aeed317a615360)
* bpo-36871: Ensure method signature is used when asserting mock calls to a ↵Miss Islington (bot)2019-08-291-0/+48
| | | | | | | | | | | | | | | | | | method (GH15577) * 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-21478: Record calls to parent when autospecced objects are used as child ↵Miss Islington (bot)2019-07-221-0/+37
| | | | | | | | | | | | | | | | with attach_mock (GH 14688) (GH-14903) * 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>
* Don't report deleted attributes in __dir__ (GHGH-10148)Miss Islington (bot)2019-06-061-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). (cherry picked from commit 0df635c7f8aa69e56a092bd4f142f0f164741ab2) Co-authored-by: Mario Corchero <mariocj89@gmail.com>
* bpo-37008: make mock_open handle able to honor next() (GH-13492)Miss Islington (bot)2019-05-232-0/+28
| | | | | | | | | | 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 (cherry picked from commit 394119afc6611f17bac96f5ec6fefa00000ae795) Co-authored-by: Damien Nadé <Anvil@users.noreply.github.com>
* bpo-31855: unittest.mock.mock_open() results now respects the argument of ↵Miss Islington (bot)2019-05-071-1/+6
| | | | | | | | | | read([size]) (GH-11521) (#13152) unittest.mock.mock_open() results now respects the argument of read([size]) Co-Authored-By: remilapeyre <remi.lapeyre@henki.fr> (cherry picked from commit 11a8832c98b3db78727312154dd1d3ba76d639ec) Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
* bpo-23078: Add support for {class,static}method to mock.create_autospec() ↵Berker Peksag2019-04-223-1/+76
| | | | | | | (GH-11613) Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com> (cherry picked from commit 9b21856b0fcda949de239edc7aa6cf3f2f4f77a3)
* bpo-36593: Fix isinstance check for Mock objects with spec executed under ↵Miss Islington (bot)2019-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 . (cherry picked from commit 830b43d03cc47a27a22a50d777f23c8e60820867) Co-authored-by: Xtreak <tir.karthi@gmail.com>
* Autospec functions should propagate mock calls to parent GH-11273 (#12039)Miss Islington (bot)2019-03-031-0/+13
| | | | | (cherry picked from commit 9c3f284de598550be6687964c23fd7599e53b20e) Co-authored-by: Xtreak <tir.karthi@gmail.com>
* bpo-35512: Resolve string target to patch.dict decorator during function ↵Miss Islington (bot)2019-02-252-0/+20
| | | | | | | | | | | | | | | | call GHGH-12000 (#12021) * 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 (cherry picked from commit a875ea58b29fbf510f9790ae1653eeaa47dc0de8) Co-authored-by: Xtreak <tir.karthi@gmail.com>
* bpo-35767: Fix unittest.loader to allow partials as test_functions ↵Miss Islington (bot)2019-01-241-0/+16
| | | | | | | (GH-11600) (#11662) (cherry picked from commit fd628cf5adaeee73eab579393cdff71c8f70cdf2) Co-authored-by: Jason Fried <me@jasonfried.info>
* bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (GH-11629)Miss Islington (bot)2019-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 (cherry picked from commit 222d303ade8aadf0adcae5190fac603bdcafe3f0) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* Add test for double patching instance methods (GH11126)Miss Islington (bot)2018-12-121-0/+14
| | | | | (cherry picked from commit 5a718e918db6211b633a7afb2bf537eb5b56cb1b) Co-authored-by: Anthony Sottile <asottile@umich.edu>
* bpo-17185: Add __signature__ to mock that can be used by inspect for ↵Miss Islington (bot)2018-12-121-0/+30
| | | | | | | | | | | | | | | | | | signature (GH11125) * 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 (cherry picked from commit f7fa62ef4422c9deee050a794fd8504640d9f8f4) Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
* [3.7] bpo-33747: Avoid mutating the global sys.modules dict in unittest.mock ↵Miss Islington (bot)2018-12-111-11/+16
| | | | | | | | | | | tests (GH-8520) (GH-11031) (cherry picked from commit 3cf74384b53b998fa846dc2590cedf9ad2a0d5fd) Co-authored-by: Anirudha Bose <ani07nov@gmail.com> https://bugs.python.org/issue33747
* bpo-35330: Don't call the wrapped object if `side_effect` is set (GH11035)Miss Islington (bot)2018-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. (cherry picked from commit f05df0a4b679d0acfd0b1fe6187ba2d553b37afa) Co-authored-by: Mario Corchero <mariocj89@gmail.com>
* bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of ↵Miss Islington (bot)2018-12-042-2/+16
| | | | | | | | _Call/_MagicProxy. (GH-10873) (#10887) Fix minor typo in test function name. (cherry picked from commit e63e617ebbe481c498bdf037a62e09f4f9f3963f) Co-authored-by: Andrew Dunai <andunai@gmail.com>
* bpo-35226: Fix equality for nested unittest.mock.call objects. (GH-10555)Miss Islington (bot)2018-12-032-0/+67
| | | | | | | Also refactor the call recording imolementation and add some notes about its limitations. (cherry picked from commit 8ca0fa9d2f4de6e69f0902790432e0ab2f37ba68) Co-authored-by: Chris Withers <chris@withers.org>
* bpo-32153: Add unit test for create_autospec with partial function returned ↵Miss Islington (bot)2018-12-031-0/+14
| | | | | | | | | | | | in getattr (GH-10398) (#10855) * Add create_autospec with partial function returned in getattr * Use self.assertFalse instead of assert * Use different names and remove object (cherry picked from commit c667b094ae37799a7e42ba5cd2ad501cc7920888) Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
* bpo-31177: Skip deleted attributes while calling reset_mock (GH-9302)Miss Islington (bot)2018-12-011-0/+10
| | | | | (cherry picked from commit edeca92c84a3b08902ecdfe987cde00c7e617887) Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
* bpo-34900: Make TestCase.debug() work with subtests (GH-9707)Miss Islington (bot)2018-10-121-0/+14
| | | | | (cherry picked from commit da2bf9f66d0c95b988c5d87646d168f65499b316) Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
* bpo-32933: Implement __iter__ method on mock_open() (GH-5974)Miss Islington (bot)2018-09-142-0/+25
| | | | | | (cherry picked from commit 2087023fdec2c89070bd14f384a3c308c548a94a) Co-authored-by: Tony Flury <anthony.flury@btinternet.com>
* bpo-33746: Fix test_unittest.testRegisterResult() in verbose mode (GH-7799)Miss Islington (bot)2018-06-201-9/+6
| | | | | | | | | | | | | | Only make sure that the result is in unittest.signals._results, don't check the full content of unittest.signals._results. support._run_suite() uses TextTestRunner in verbose mode, but TextTestRunner.run() calls registerResult(result) which made the test fail with "odd object in result set". Call also removeResult() to restore unittest.signals._results to avoid test side effect. (cherry picked from commit fd8fbce495c32b0cbc13f71a8e9d4eec6f48c844) Co-authored-by: Victor Stinner <vstinner@redhat.com>
* bpo-33748: fix tests altering sys.path and sys.modules (GH-7433) (#7604)Miss Islington (bot)2018-06-101-19/+20
| | | | | (cherry picked from commit 4ab4695388fb9ec03a14d93e90ce50d832a920ec) Co-authored-by: Tal Einat <taleinat+github@gmail.com>
* [3.7] bpo-32746: Fix multiple typos (GH-5144) (GH-5520)Miss Islington (bot)2018-02-041-2/+2
| | | | | | Fix typos found by codespell in docs, docstrings, and comments. (cherry picked from commit c3d9508ff22ece9a96892b628dd5813e2fb0cd80) Co-authored-by: Leo Arias <leo.arias@canonical.com>
* bpo-32593: Drop FreeBSD 9 and older support (#5232)Victor Stinner2018-01-221-8/+0
| | | Drop support of FreeBSD 9 and older.
* bpo-32297: Few misspellings found in Python source code comments. (#4803)Mike2017-12-141-1/+1
| | | | | | | | * Fix multiple typos in code comments * Add spacing in comments (test_logging.py, test_math.py) * Fix spaces at the beginning of comments in test_logging.py
* bpo-32230: Set sys.warnoptions with -X dev (#4820)Victor Stinner2017-12-121-1/+1
| | | | | | | | | | | | | | Rather than supporting dev mode directly in the warnings module, this instead adjusts the initialisation code to add an extra 'default' entry to sys.warnoptions when dev mode is enabled. This ensures that dev mode behaves *exactly* as if `-Wdefault` had been passed on the command line, including in the way it interacts with `sys.warnoptions`, and with other command line flags like `-bb`. Fix also bpo-20361: have -b & -bb options take precedence over any other warnings options. Patch written by Nick Coghlan, with minor modifications of Victor Stinner.
* bpo-32071: Fix regression and add What's New entry (#4589)Jonas Haag2017-11-281-0/+23
| | | | | | * bpo-32071: Fix an undocumented behaviour regression * bpo-32071: Add 3.7 release note entry for unittest -k
* bpo-32071: Add unittest -k option (#4496)Jonas Haag2017-11-252-0/+55
| | | | * bpo-32071: Add unittest -k option
* Fix miscellaneous typos (#4275)luzpaz2017-11-051-1/+1
|
* bpo-30541: Add new method to seal mocks (GH61923)Mario Corchero2017-10-171-0/+181
| | | | | | | The new method allows the developer to control when to stop the feature of mocks that automagically creates new mocks when accessing an attribute that was not declared before Signed-off-by: Mario Corchero <mariocj89@gmail.com>
* Spelling fixes (#2902)Ville Skyttä2017-08-031-1/+1
|
* bpo-29403: Fix mock's broken autospec behavior on method-bound builtin ↵Aaron Gallagher2017-07-201-0/+15
| | | | | | | | | | | | | | | | | | | functions (GH-3) Cython will, in the right circumstances, offer a MethodType instance where im_func is a builtin function. Any instance of MethodType is automatically assumed to be a Python-defined function (more specifically, a function that has an inspectable signature), but _set_signature was still conservative in its assumptions. As a result _set_signature would return early with None instead of a mock since the im_func had no inspectable signature. This causes problems deeper inside mock, as _set_signature is assumed to _always_ return a mock, and nothing checked its return value. In similar corner cases, autospec will simply not check the spec of the function, so _set_signature is amended to now return early with the original, not-wrapped mock object. Patch by Aaron Gallagher.
* bpo-30813: Fix unittest when hunting refleaks (#2502)Victor Stinner2017-06-301-0/+6
| | | | | | bpo-11798, bpo-16662, bpo-16935, bpo-30813: Skip test_discover_with_module_that_raises_SkipTest_on_import() and test_discover_with_init_module_that_raises_SkipTest_on_import() of test_unittest when hunting reference leaks using regrtest.
* bpo-30664: The description of a unittest subtest now preserves the (#2265)Serhiy Storchaka2017-06-231-5/+14
| | | | order of keyword arguments of TestCase.subTest().
* #30190: fix invalid escape sequence warnings (#1534)Giampaolo Rodola2017-05-101-3/+3
|
* bpo-30190: improved error msg for assertAlmostEqual(delta=...) (#1331)Giampaolo Rodola2017-05-011-3/+5
| | | | | | | | | | | | * #30190 / unittest / assertAlmostEqual(delta=...) / error msg: show the difference between the 2 numbers in case of failure * safe_repr() diff * also show difference when passing 'places' argument * refactoring * update Misc/NEWS
* bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051)Serhiy Storchaka2017-04-161-2/+2
|
* Fix ref cycles in TestCase.assertRaises() (#193)Victor Stinner2017-03-271-0/+13
| | | | bpo-23890: unittest.TestCase.assertRaises() now manually breaks a reference cycle to not keep objects alive longer than expected.
* bpo-28961: Address my comments from earlier code review (#305)Berker Peksag2017-02-261-12/+3
|
* 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 #28735: Fixed the comparison of mock.MagickMock with mock.ANY.Serhiy Storchaka2017-01-211-3/+14
| | |
* | | Issue 29274: Merge doc fixes from 3.6Martin Panter2017-01-181-4/+4
|\ \ \ | |/ /
| * | Issue 29274: Merge doc fixes from 3.5Martin Panter2017-01-181-4/+4
| |\ \ | | |/
| | * Issue #29274: tests cases → test casesMartin Panter2017-01-181-4/+4
| | |