| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
| |
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).
|
|
|
|
|
| |
(GH-11613)
Co-authored-by: Felipe <felipe.nospam.ochoa@gmail.com>
|
|
|
|
|
| |
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 .
|
|
|
|
|
|
| |
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
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
message. (GH-11804)
|
|
|
|
|
|
|
|
| |
* 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
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
* 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.
|
|
|
|
|
| |
_Call/_MagicProxy. (#10873)
Fix minor typo in test function name.
|
|
|
|
| |
Also refactor the call recording imolementation and add some notes
about its limitations.
|
| |
|
|
|
|
|
|
|
|
|
|
| |
(GH-10284)
Two kind of mistakes:
1. Missed space. After concatenating there is no space between words.
2. Missed comma. Causes unintentional concatenating in a list of strings.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
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.
|
|
|
|
|
| |
The docs in `library/unittest.mock` have been updated to remove
confusing terms about submock and be explicit about the behavior
expected.
|
| |
|
|
|
|
|
| |
This makes the assertion error message more useful, aiding debugging.
Thanks @davidair!
|
| |
|
|
|
| |
unittest.mock.MagicMock now supports the __round__() magic method.
|
|
|
|
|
|
|
| |
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.
|
| |
|
|\ |
|
| |\ |
|
| | | |
|
| | |
| | |
| | |
| | | |
identity when they are copied or pickled.
|
|\ \ \
| |/ / |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Issue #28961: Fix unittest.mock._Call helper: don't ignore the name parameter
anymore.
Patch written by Jiajun Huang.
|
|/ /
| |
| |
| | |
Patch by Jiajun Huang.
|
| |
| |
| |
| | |
assert_called, assert_not_called, and assert_called_once.
|
|\ \
| |/
| |
| | |
_is_data_descriptor().
|
| |
| |
| |
| | |
_is_data_descriptor().
|
|\ \
| |/
| |
| |
| | |
subclasses of property() and other data descriptors. Removes the never
publicly used, never documented unittest.mock.DescriptorTypes tuple.
|
| |
| |
| |
| | |
for subclasses of property() and other data descriptors.
|
|\ \
| |/ |
|
| | |
|
|\ \
| |/ |
|
| | |
|
| |
| |
| |
| |
| | |
We now have two keyword only parameters in the reset_mock function to
selectively reset the return_value or the side_effects, or both.
|
|\ \
| |/
| |
| | |
Patch from Yolanda Robla.
|
| |
| |
| |
| | |
Patch from Yolanda Robla.
|
|\ \
| |/
| |
| |
| |
| |
| | |
_Call is a subclass of tuple (changeset 3603bae63c13 only works
for classes) so we need to implement __ne__ ourselves.
Patch by Andrew Plummer.
|
| |
| |
| |
| |
| |
| |
| | |
_Call is a subclass of tuple (changeset 3603bae63c13 only works
for classes) so we need to implement __ne__ ourselves.
Patch by Andrew Plummer.
|
| |
| |
| |
| |
| | |
Issue #26323: Add assert_called() and assert_called_once() methods to
unittest.mock.Mock.
|