diff options
author | 2020-03-09 15:34:12 -0700 | |
---|---|---|
committer | 2020-03-13 17:11:28 -0700 | |
commit | 7e7c538435c899f45ff277e05fb59d139f401954 (patch) | |
tree | a0e362fdc7f2d458d13ea41a64ae0badd98efd6d /tests | |
parent | Cog tests: fix duplicate commands being yielded (diff) |
Cog tests: add a test for duplicate command names & aliases
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bot/cogs/test_cogs.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/bot/cogs/test_cogs.py b/tests/bot/cogs/test_cogs.py index 9d1d4ebea..616f5f44a 100644 --- a/tests/bot/cogs/test_cogs.py +++ b/tests/bot/cogs/test_cogs.py @@ -4,6 +4,7 @@ import importlib import pkgutil import typing as t import unittest +from collections import defaultdict from types import ModuleType from discord.ext import commands @@ -56,3 +57,19 @@ class CommandNameTests(unittest.TestCase): for cog in self.walk_cogs(module): for cmd in self.walk_commands(cog): yield cmd + + def test_names_dont_shadow(self): + """Names and aliases of commands should be unique.""" + all_names = defaultdict(list) + for cmd in self.get_all_commands(): + func_name = f"{cmd.module}.{cmd.callback.__qualname__}" + + for name in self.get_qualified_names(cmd): + with self.subTest(cmd=func_name, name=name): + if name in all_names: + conflicts = ", ".join(all_names.get(name, "")) + self.fail( + f"Name '{name}' of the command {func_name} conflicts with {conflicts}." + ) + + all_names[name].append(func_name) |