| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
| |
TestCase.shortDescription (GH-18321)
(cherry picked from commit 032de7324e30c6b44ef272cea3be205a3d768759)
Co-authored-by: Steve Cirelli <scirelli+git@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
| |
(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>
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
| |
(GH-11613)
Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
(cherry picked from commit 9b21856b0fcda949de239edc7aa6cf3f2f4f77a3)
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
| |
(cherry picked from commit 9c3f284de598550be6687964c23fd7599e53b20e)
Co-authored-by: Xtreak <tir.karthi@gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
| |
(GH-11600) (#11662)
(cherry picked from commit fd628cf5adaeee73eab579393cdff71c8f70cdf2)
Co-authored-by: Jason Fried <me@jasonfried.info>
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
|
|
|
|
| |
(cherry picked from commit 5a718e918db6211b633a7afb2bf537eb5b56cb1b)
Co-authored-by: Anthony Sottile <asottile@umich.edu>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
| |
tests (GH-8520) (GH-11031)
(cherry picked from commit 3cf74384b53b998fa846dc2590cedf9ad2a0d5fd)
Co-authored-by: Anirudha Bose <ani07nov@gmail.com>
https://bugs.python.org/issue33747
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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>
|
|
|
|
|
|
|
|
| |
_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>
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
| |
(cherry picked from commit edeca92c84a3b08902ecdfe987cde00c7e617887)
Co-authored-by: Xtreak <tirkarthi@users.noreply.github.com>
|
|
|
|
|
| |
(cherry picked from commit da2bf9f66d0c95b988c5d87646d168f65499b316)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
|
|
|
|
|
|
| |
(cherry picked from commit 2087023fdec2c89070bd14f384a3c308c548a94a)
Co-authored-by: Tony Flury <anthony.flury@btinternet.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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>
|
|
|
|
|
| |
(cherry picked from commit 4ab4695388fb9ec03a14d93e90ce50d832a920ec)
Co-authored-by: Tal Einat <taleinat+github@gmail.com>
|
|
|
|
|
|
| |
Fix typos found by codespell in docs, docstrings, and comments.
(cherry picked from commit c3d9508ff22ece9a96892b628dd5813e2fb0cd80)
Co-authored-by: Leo Arias <leo.arias@canonical.com>
|
|
|
| |
Drop support of FreeBSD 9 and older.
|
|
|
|
|
|
|
|
| |
* 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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 an undocumented behaviour regression
* bpo-32071: Add 3.7 release note entry for unittest -k
|
|
|
|
| |
* bpo-32071: Add unittest -k option
|
| |
|
|
|
|
|
|
|
| |
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>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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-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.
|
|
|
|
| |
order of keyword arguments of TestCase.subTest().
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
* #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-23890: unittest.TestCase.assertRaises() now manually breaks a
reference cycle to not keep objects alive longer than expected.
|
| |
|
|\ |
|
| |\ |
|
| | | |
|
|\ \ \
| |/ / |
|
| |\ \
| | |/ |
|
| | | |
|