aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGravatar wookie184 <[email protected]>2024-05-24 21:33:45 +0000
committerGravatar GitHub <[email protected]>2024-05-25 01:24:14 +0000
commit36fac4980ea2316e346b8718ffbe8b1f65211729 (patch)
treeb3525e586cc38b389f8598b5bceebd66cfe2ba08 /tests
parentMerge pull request #3075 from python-discord/use-coverage-sysmon (diff)
Lazily create `guild` on text/voice channel mocks
In many cases the Guild mock is not needed so this makes tests faster
Diffstat (limited to 'tests')
-rw-r--r--tests/helpers.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/tests/helpers.py b/tests/helpers.py
index c51a82a9d..1164828d6 100644
--- a/tests/helpers.py
+++ b/tests/helpers.py
@@ -388,12 +388,17 @@ class MockTextChannel(CustomMockMixin, unittest.mock.Mock, HashableMixin):
spec_set = text_channel_instance
def __init__(self, **kwargs) -> None:
- default_kwargs = {"id": next(self.discord_id), "name": "channel", "guild": MockGuild()}
+ default_kwargs = {"id": next(self.discord_id), "name": "channel"}
super().__init__(**collections.ChainMap(kwargs, default_kwargs))
if "mention" not in kwargs:
self.mention = f"#{self.name}"
+ @cached_property
+ def guild(self) -> MockGuild:
+ """Cached guild property."""
+ return MockGuild()
+
class MockVoiceChannel(CustomMockMixin, unittest.mock.Mock, HashableMixin):
"""
@@ -405,12 +410,17 @@ class MockVoiceChannel(CustomMockMixin, unittest.mock.Mock, HashableMixin):
spec_set = voice_channel_instance
def __init__(self, **kwargs) -> None:
- default_kwargs = {"id": next(self.discord_id), "name": "channel", "guild": MockGuild()}
+ default_kwargs = {"id": next(self.discord_id), "name": "channel"}
super().__init__(**collections.ChainMap(kwargs, default_kwargs))
if "mention" not in kwargs:
self.mention = f"#{self.name}"
+ @cached_property
+ def guild(self) -> MockGuild:
+ """Cached guild property."""
+ return MockGuild()
+
# Create data for the DMChannel instance
state = unittest.mock.MagicMock()