diff options
author | 2019-11-13 16:06:51 +0100 | |
---|---|---|
committer | 2019-11-13 16:16:22 +0100 | |
commit | bf7720f16fa69716f15b16e3dcd0f20c186958b8 (patch) | |
tree | 24374b105199ce28b991707180f7fbbe608d25bb /tests | |
parent | Prevent unwanted logging while running tests (diff) |
Allow `name` attribute to be set during Mock init
The `name` keyword argument has a special meaning for the default
mockobjects provided by `unittest.mock`. This means that by default,
the common d.py `name` attribute can't be set during initalization of
one of our custom Mock-objects by passing it to the constructor.
Since it's unlikely for us to make use of the special `name` feature
of mocks and more likely to want to set the d.py `name` attribute, I
added special handling of the `name` kwarg.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/helpers.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py index 8d661513d..5dc7a0d2f 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -74,7 +74,10 @@ class CustomMockMixin: child_mock_type = unittest.mock.MagicMock def __init__(self, spec: Any = None, **kwargs): + name = kwargs.pop('name', None) # `name` has special meaning for Mock classes, so we need to set it manually. super().__init__(spec=spec, **kwargs) + if name: + self.name = name if spec: self._extract_coroutine_methods_from_spec_instance(spec) |