diff options
author | 2020-03-09 13:31:44 -0700 | |
---|---|---|
committer | 2020-03-13 17:11:03 -0700 | |
commit | d9ed24922f6daa17d625b345cb195e7fae7758cc (patch) | |
tree | 21044ae713c1e6fa5fec863bcb4b79381015e4c4 | |
parent | Cog tests: add a function to get all commands (diff) |
Cog tests: add a function to get all extensions
-rw-r--r-- | tests/bot/cogs/test_cogs.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/bot/cogs/test_cogs.py b/tests/bot/cogs/test_cogs.py index b128ca123..386299fb1 100644 --- a/tests/bot/cogs/test_cogs.py +++ b/tests/bot/cogs/test_cogs.py @@ -1,10 +1,15 @@ """Test suite for general tests which apply to all cogs.""" +import importlib +import pkgutil import typing as t import unittest +from types import ModuleType from discord.ext import commands +from bot import cogs + class CommandNameTests(unittest.TestCase): """Tests for shadowing command names and aliases.""" @@ -17,3 +22,9 @@ class CommandNameTests(unittest.TestCase): yield command if isinstance(command, commands.GroupMixin): yield from command.walk_commands() + + @staticmethod + def walk_extensions() -> t.Iterator[ModuleType]: + """Yield imported extensions (modules) from the bot.cogs subpackage.""" + for module in pkgutil.iter_modules(cogs.__path__, "bot.cogs."): + yield importlib.import_module(module.name) |