I'd like to add tests to this project. However, setting everything up as-is would require one of two (undesirable) paths forward:
Building a second bot to feed input and test responses,
Using another testing library ( like dpytest ) which is still in development and not clearly documented yet
I prefer a third option, which is to move all of the "work" code into non-discord, easily-testable files. For example:
# before
@commands.command()
async def add_numbers(self, ctx, *args):
result = sum(args)
ctx.channel.send(f"The sum is {result}")
# after
import myCommands
@commands.command()
async def add_numbers(self, ctx, *args):
result = myCommands.add_numbers(args)
ctx.channel.send(f"The sum is {result}")
With the latter implementation, we can now implement test_add_numbers() without needing to worry about any of the async/websocket Discord api stuff.
I'd like to add tests to this project. However, setting everything up as-is would require one of two (undesirable) paths forward:
I prefer a third option, which is to move all of the "work" code into non-discord, easily-testable files. For example:
With the latter implementation, we can now implement
test_add_numbers()
without needing to worry about any of the async/websocket Discord api stuff.