aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index d444cc49d..1ab8b455f 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -24,12 +24,25 @@ for logger in logging.Logger.manager.loggerDict.values():
def autospec(target, *attributes: str, **kwargs) -> unittest.mock._patch:
- """Patch multiple `attributes` of a `target` with autospecced mocks and `spec_set` as True."""
+ """
+ Patch multiple `attributes` of a `target` with autospecced mocks and `spec_set` as True.
+
+ To allow for arbitrary parameter names to be used by the decorated function, the patchers have
+ no attribute names associated with them. As a consequence, it will not be possible to retrieve
+ mocks by their attribute names when using this as a context manager,
+ """
# Caller's kwargs should take priority and overwrite the defaults.
kwargs = {'spec_set': True, 'autospec': True, **kwargs}
attributes = {attribute: unittest.mock.DEFAULT for attribute in attributes}
- return unittest.mock.patch.multiple(target, **attributes, **kwargs)
+ patcher = unittest.mock.patch.multiple(target, **attributes, **kwargs)
+
+ # Unset attribute names to allow arbitrary parameter names for the decorator function.
+ patcher.attribute_name = None
+ for additional_patcher in patcher.additional_patchers:
+ additional_patcher.attribute_name = None
+
+ return patcher
class HashableMixin(discord.mixins.EqualityComparable):