Commit Graph

274 Commits

Author SHA1 Message Date
Xtreak 9c3f284de5 Autospec functions should propagate mock calls to parent GH-11273 2019-02-25 21:46:34 +00:00
Xtreak a875ea58b2 bpo-35512: Resolve string target to patch.dict decorator during function 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
2019-02-24 18:54:49 +00:00
Susan Su 2bdd5858e3 bpo-35500: align expected and actual calls on mock.assert_called_with error message. (GH-11804) 2019-02-13 18:22:29 -08:00
Jason Fried fd628cf5ad bpo-35767: Fix unittest.loader to allow partials as test_functions (#11600) 2019-01-23 21:57:25 +01:00
Pablo Galindo 222d303ade bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)
* 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
2019-01-21 08:57:46 +00:00
Anthony Sottile 5a718e918d Add test for double patching instance methods (#11085) 2018-12-12 07:56:35 +00:00
Xtreak f7fa62ef44 bpo-17185: Add __signature__ to mock that can be used by inspect for 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
2018-12-12 07:54:54 +00:00
Mario Corchero f05df0a4b6 bpo-35330: Don't call the wrapped object if `side_effect` is set (GH10973)
* 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.
2018-12-08 11:25:02 +00:00
Anirudha Bose 3cf74384b5 bpo-33747: Avoid mutating the global sys.modules dict in unittest.mock tests (GH-8520) 2018-12-07 15:30:42 -08:00
Mario Corchero 20428527a7 Remove unused function in `testmock/support.py` (GH-10975)
The function is never imported and the implementation is actually buggy.
As `warnings.catch_warnings` is not imported here.
2018-12-06 17:05:46 +00:00
Andrew Dunai e63e617ebb bpo-35357: Add _mock_ prefix to name/parent/from_kall attributes of _Call/_MagicProxy. (#10873)
Fix minor typo in test function name.
2018-12-04 09:08:45 +00:00
Chris Withers 8ca0fa9d2f
bpo-35226: Fix equality for nested unittest.mock.call objects. (#10555)
Also refactor the call recording imolementation and add some notes
about its limitations.
2018-12-03 21:31:37 +00:00
Xtreak c667b094ae bpo-32153: Add unit test for create_autospec with partial function returned in getattr (#10398)
* Add create_autospec with partial function returned in getattr

* Use self.assertFalse instead of assert

* Use different names and remove object
2018-12-03 07:58:15 +00:00
Xtreak edeca92c84 bpo-31177: Skip deleted attributes while calling reset_mock (GH-9302) 2018-12-01 11:03:54 +01:00
Xtreak b2774c8e91 Use assertEqual to fix DeprecationWarning. (GH-10794) 2018-11-29 15:07:00 +02:00
Lisa Roach 0f221d09ca
bpo-24412: Adds cleanUps for setUpClass and setUpModule. (GH-9190) 2018-11-08 18:34:33 -08:00
Petter Strandmark 47d94241a3 bpo-35047, unittest.mock: Better error messages on assert_called_xxx failures (GH-10090)
unittest.mock now includes mock calls in exception messages if
assert_not_called, assert_called_once, or assert_called_once_with
fails.
2018-10-28 21:37:10 +01:00
Max Bélanger 6c83d9f4a7 bpo-35022: unittest.mock.MagicMock now also supports __fspath__ (GH-9960)
The MagicMock class supports many magic methods, but not __fspath__. To ease
testing with modules such as os.path, this function is now supported by default.
2018-10-25 23:48:58 +02:00
Bruno Oliveira da2bf9f66d bpo-34900: Make TestCase.debug() work with subtests (GH-9707) 2018-10-12 13:35:55 +03:00
Tony Flury 2087023fde bpo-32933: Implement __iter__ method on mock_open() (GH-5974) 2018-09-13 01:21:16 +03:00
Serhiy Storchaka 77d5781835
bpo-34318: Convert deprecation warnings to errors in assertRaises() etc. (GH-8623) 2018-08-19 10:00:11 +03:00
Victor Stinner fd8fbce495
bpo-33746: Fix test_unittest.testRegisterResult() in verbose mode (GH-7799)
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.
2018-06-20 11:29:33 +02:00
Tal Einat 4ab4695388
bpo-33748: fix tests altering sys.path and sys.modules (GH-7433) 2018-06-10 10:10:28 +03:00
John Reese 6c4fab0f4b bpo-33516: Add support for __round__ in MagicMock (GH-6880)
unittest.mock.MagicMock now supports the __round__() magic method.
2018-05-22 22:01:10 +02:00
Leo Arias c3d9508ff2 bpo-32746: Fix multiple typos (GH-5144)
Fix typos found by codespell in docs, docstrings, and comments.
2018-02-03 19:36:10 -05:00
Victor Stinner 13ff24582c
bpo-32593: Drop FreeBSD 9 and older support (#5232)
Drop support of FreeBSD 9 and older.
2018-01-22 18:32:50 +01:00
Mike 53f7a7c281 bpo-32297: Few misspellings found in Python source code comments. (#4803)
* 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
2017-12-14 13:04:53 +02:00
Victor Stinner 747f48e2e9
bpo-32230: Set sys.warnoptions with -X dev (#4820)
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.
2017-12-12 22:59:48 +01:00
Jonas Haag 4d193bcc25 bpo-32071: Fix regression and add What's New entry (#4589)
* bpo-32071: Fix an undocumented behaviour regression

* bpo-32071: Add 3.7 release note entry for unittest -k
2017-11-28 20:40:44 +01:00
Jonas Haag 5b48dc638b bpo-32071: Add unittest -k option (#4496)
* bpo-32071: Add unittest -k option
2017-11-25 16:23:52 +01:00
luzpaz a5293b4ff2 Fix miscellaneous typos (#4275) 2017-11-05 15:37:50 +02:00
Mario Corchero 552be9d7e6 bpo-30541: Add new method to seal mocks (GH61923)
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>
2017-10-17 04:35:11 -07:00
Ville Skyttä 49b2734bf1 Spelling fixes (#2902) 2017-08-03 09:00:59 +03:00
Aaron Gallagher 856cbcc12f bpo-29403: Fix mock's broken autospec behavior on method-bound builtin 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.
2017-07-20 03:01:14 +03:00
Victor Stinner e4f9a2d2be bpo-30813: Fix unittest when hunting refleaks (#2502)
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.
2017-06-30 12:52:52 +02:00
Serhiy Storchaka 48fbe52ac7 bpo-30664: The description of a unittest subtest now preserves the (#2265)
order of keyword arguments of TestCase.subTest().
2017-06-23 21:47:39 +03:00
Giampaolo Rodola c4750959ac #30190: fix invalid escape sequence warnings (#1534) 2017-05-10 20:13:20 +02:00
Giampaolo Rodola 5d7a8d0c13 bpo-30190: improved error msg for assertAlmostEqual(delta=...) (#1331)
* #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
2017-05-01 18:18:56 +02:00
Serhiy Storchaka 55fe1ae970 bpo-30022: Get rid of using EnvironmentError and IOError (except test… (#1051) 2017-04-16 10:46:38 +03:00
Victor Stinner bbd3cf8f1e Fix ref cycles in TestCase.assertRaises() (#193)
bpo-23890: unittest.TestCase.assertRaises() now manually breaks a
reference cycle to not keep objects alive longer than expected.
2017-03-28 00:56:28 +02:00
Berker Peksag 5aa3856b4f bpo-28961: Address my comments from earlier code review (#305) 2017-02-26 15:04:11 +03:00
Serhiy Storchaka 19dea2c726 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:17:25 +02:00
Serhiy Storchaka a203360836 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:15:18 +02:00
Serhiy Storchaka 362f058a89 Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY. 2017-01-21 23:12:58 +02:00
Martin Panter 9722d7f142 Issue 29274: Merge doc fixes from 3.6 2017-01-18 12:11:42 +00:00
Martin Panter 4710935b11 Issue 29274: Merge doc fixes from 3.5 2017-01-18 12:11:12 +00:00
Martin Panter 37f183d43d Issue #29274: tests cases → test cases 2017-01-18 12:06:38 +00:00
Serhiy Storchaka d9c956fb23 Issue #20804: The unittest.mock.sentinel attributes now preserve their
identity when they are copied or pickled.
2017-01-11 20:13:03 +02:00
Victor Stinner 84b6fb0eea Fix unittest.mock._Call: don't ignore name
Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter
anymore.

Patch written by Jiajun Huang.
2017-01-06 18:15:51 +01:00
Gregory P. Smith ac5084b6c7 Fixes issue28380: unittest.mock Mock autospec functions now properly support
assert_called, assert_not_called, and assert_called_once.
2016-10-06 14:31:23 -07:00