-
We should build some tests for the Python Discord Bot, Do we use the Pytest or unittest module? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
This entirely depends on what you plan to test. Both actually work pretty great, but if you choose to automate the testing using GitHub Actions or any other CI/CD service, I think Pytest is the way to go. Pytest is easily installable and can be integrated into the project with ease. All it takes is the testing functions with the Also since the bot's written in Run the following command in your terminal window to install Pytest with async support: $ pip install pytest-asyncio An example followed by the installation: from main import bot # considering you have already defined bot as an object in your main.py file
import pytest
@pytest.mark.asyncio # The decorator to mark the function as asynchronous / coroutine.
class TestTheBot: # The class which will contain the test functions.
async def testwhatever(self) -> None:
assert bot.do_something() == 'whatever it is' |
Beta Was this translation helpful? Give feedback.
This entirely depends on what you plan to test. Both actually work pretty great, but if you choose to automate the testing using GitHub Actions or any other CI/CD service, I think Pytest is the way to go. Pytest is easily installable and can be integrated into the project with ease. All it takes is the testing functions with the
assert
keyword and an installed copy of Pytest.Also since the bot's written in
async/await
syntax, you'd probably wanna go with the pytest-asyncio package since it supports coroutines as test functions.Run the following command in your terminal window to install Pytest with async support:
An example followed by the installation: