Successfully set up comprehensive testing infrastructure for the Discord bot project using pytest.
pytest==9.0.2- Core testing frameworkpytest-asyncio==1.3.0- Async/await supportpytest-cov==7.0.0- Code coverage reportingpytest-mock==3.15.1- Mocking utilities
All dependencies added to requirements.txt (lines 13-16).
tests/
├── __init__.py
├── conftest.py
├── test_setup.py
├── utils/
│ └── __init__.py
├── cogs/
│ └── __init__.py
└── ui/
└── __init__.py
File: pytest.ini
asyncio_mode = auto- Automatic async test detection- Coverage reports: HTML, terminal, and XML formats
- Verbose output enabled
- Test discovery patterns configured
File: tests/conftest.py
Provides reusable fixtures:
event_loop- Async event loop managementmock_discord_context- Mock Discord context with send(), author, guild, channelmock_discord_bot- Mock bot object with user infomock_discord_message- Mock message with edit/delete methods
File: tests/test_setup.py
Test suite with 4 passing tests:
test_pytest_installed- Verifies pytest workstest_basic_assertion- Basic assertion testtest_async_support- Async/await functionalitytest_fixtures_available- Fixture availability
============================= test session starts =============================
platform win32 -- Python 3.13.11, pytest-9.0.2, pluggy-1.6.0
collected 4 items
tests/test_setup.py::TestSetup::test_pytest_installed PASSED [ 25%]
tests/test_setup.py::TestSetup::test_basic_assertion PASSED [ 50%]
tests/test_setup.py::TestSetup::test_async_support PASSED [ 75%]
tests/test_setup.py::TestSetup::test_fixtures_available PASSED [100%]
============================== 4 passed in 0.37s ==============================
- HTML report:
htmlcov/index.html - XML report:
coverage.xml - Terminal report: Included in test output
Ready for Task 2: Write unit tests for utility modules (dice, music, initiative, character_storage)
Run all tests:
pytestRun specific test file:
pytest tests/test_setup.py -vRun with coverage:
pytest --cov=. --cov-report=htmlRun async tests only:
pytest -m asyncio