uchill/backend/scripts/test_performance.py

61 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
"""
Скрипт для запуска тестов производительности и вывода результатов.
Использование: python scripts/test_performance.py
"""
import os
import sys
import django
# Добавляем путь к проекту
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Настраиваем Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
import subprocess
import json
def run_performance_tests():
"""Запускает тесты производительности и выводит результаты."""
print("=" * 60)
print("🚀 Запуск тестов производительности API")
print("=" * 60)
# Запускаем pytest с маркером performance
# Используем python -m pytest для надежности в Windows
cmd = [
sys.executable, '-m', 'pytest',
'-v',
'-m', 'performance',
'--tb=short',
'--capture=no', # Показываем print'ы
'apps/homework/tests/test_performance.py',
]
# Получаем корневую директорию проекта (где manage.py)
script_dir = os.path.dirname(os.path.abspath(__file__))
project_root = os.path.dirname(script_dir)
result = subprocess.run(
cmd,
cwd=project_root,
capture_output=False
)
print("\n" + "=" * 60)
if result.returncode == 0:
print("Все тесты производительности пройдены успешно!")
else:
print("⚠️ Некоторые тесты не прошли. Проверьте вывод выше.")
print("=" * 60)
return result.returncode == 0
if __name__ == '__main__':
success = run_performance_tests()
sys.exit(0 if success else 1)