SKILL.md
pytest_asyncio
pytest es el framework de testing principal del sistema KYC. pytest-asyncio añade soporte para tests de funciones async def, indispensable dado que todos los agentes son async. pytest-cov mide la cobertura de tests.
When to use
Usar para todos los tests: unitarios, de integración y de regresión. Ningún código nuevo debe llegar a main sin tests que cubran el happy path y los edge cases críticos.
Instructions
- Instalar:
pip install pytest pytest-asyncio pytest-cov httpx - Configurar en
pyproject.toml:
``toml [tool.pytest.inioptions] asynciomode = "auto" testpaths = ["backend/tests"] addopts = "--cov=backend --cov-report=xml --cov-fail-under=80" ``
- Estructura de tests:
`` backend/tests/ ├── unit/ │ ├── testlivenessagent.py │ ├── testocragent.py │ └── testfacematchagent.py ├── integration/ │ ├── testpipelinee2e.py │ └── testapi_endpoints.py └── conftest.py ``
- Test async example:
``python import pytest from httpx import AsyncClient from backend.main import app @pytest.mark.asyncio async def testverifyendpointreturns200(): async with AsyncClient(app=app, baseurl="http://test") as client: response = await client.post("/v1/verify", json={"sessionid": "test-123"}) assert response.status_code == 200 ``
- Fixtures en
conftest.py: mock de modelos ML (devolver scores fijos), conexión a Redis de test, factory de sesiones. - Tests críticos obligatorios: threshold de liveness, threshold de face match, rechazo de documento expirado, rate limiting.
Notes
asyncio_mode = "auto"hace que todos los tests async se ejecuten sin@pytest.mark.asyncioen cada función.- Mockear los modelos ML con
pytest-mockounittest.mockpara tests unitarios rápidos — los tests con modelos reales van en tests de integración. httpx.AsyncClientpermite testear endpoints FastAPI sin levantar un servidor real.