Corrección de tests en Django Rest Framework
Introducción
En este documento se describen los pasos necesarios para corregir los tests de Django Rest Framework.
Actualmente tenemos el siguiente error en los tests:
================================================== test session starts ===================================================
platform linux -- Python 3.12.3, pytest-8.2.0, pluggy-1.5.0
rootdir: /home/statick/workspaces/Curso_django_and_react/inventario_django
collected 0 items / 1 error
========================================================= ERRORS =========================================================
________________________________________ ERROR collecting productos/test_views.py ________________________________________
ImportError while importing test module '/home/statick/workspaces/Curso_django_and_react/inventario_django/productos/test_views.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib64/python3.12/importlib/__init__.py:90: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
productos/test_views.py:1: in <module>
from django.urls import reverse
E ModuleNotFoundError: No module named 'django'
================================================ short test summary info =================================================
ERROR productos/test_views.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==================================================== 1 error in 0.07s ====================================================
Pasos
1. Crear un entorno virtual
python3 -m venv venv
2. Activar el entorno virtual
source venv/bin/activate
3. Instalar las dependencias
pip install -r requirements.txt
4. Correr los tests
pytest
5. Corregir los tests
Para corregir los tests, se debe modificar el archivo productos/test_views.py
y corregir el error de importación.
6. Correr los tests nuevamente
pytest
7. Desactivar el entorno virtual
deactivate
Conclusión
Una vez corregidos los tests, se debe hacer un pull request al repositorio original.