aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/helpers.py')
-rw-r--r--tests/helpers.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index 2b79a6c2a..d444cc49d 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -23,6 +23,15 @@ for logger in logging.Logger.manager.loggerDict.values():
logger.setLevel(logging.CRITICAL)
+def autospec(target, *attributes: str, **kwargs) -> unittest.mock._patch:
+ """Patch multiple `attributes` of a `target` with autospecced mocks and `spec_set` as True."""
+ # 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)
+
+
class HashableMixin(discord.mixins.EqualityComparable):
"""
Mixin that provides similar hashing and equality functionality as discord.py's `Hashable` mixin.