This guide covers testing for the HyperCode V2.0 Backend and related services.
Test Stack
- pytest: Test Runner
- pytest-asyncio: Async Test Support
- httpx: Async HTTP Client
- ruff: Fast Python Linter
- pip-audit: Dependency Vulnerability Scanner
Ensure you have the development dependencies installed:
cd backend
pip install -r requirements-dev.txtExecute the full test suite with coverage:
pytest -v --cov=app --cov-report=term-missingTo run only the health check tests:
pytest -k "test_health_check"The project uses GitHub Actions for Continuous Integration.
Workflow File: .github/workflows/ci-python.yml
- Checkout: Clones the repository.
- Install Deps: Installs
requirements.txtandrequirements-dev.txt. - Run Tests: Executes
pytestwith coverage tracking. - Coverage Check: Fails if coverage drops below the threshold (currently 10%).
- Audit: Scans dependencies for known vulnerabilities (
pip-audit,safety).
All tests reside in backend/app/tests/.
# backend/app/tests/test_example.py
import pytest
from httpx import AsyncClient
from app.main import app
@pytest.mark.asyncio
async def test_example_endpoint():
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.get("/api/v1/example")
assert response.status_code == 200Use unittest.mock or pytest-mock to mock external services (e.g., Database, Redis, Brain API).
"ModuleNotFoundError: No module named 'app'"
Ensure you are running pytest from the backend/ directory, or set PYTHONPATH:
$env:PYTHONPATH="C:\path\to\HyperCode-V2.0\backend"
pytest"Asyncio Loop Error"
Ensure your test functions are marked with @pytest.mark.asyncio.