Files
prod/count_tests.py

78 lines
2.9 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 python3
"""
Скрипт для подсчета количества тестов в проекте
"""
import subprocess
import sys
import os
def count_tests_in_directory(directory):
"""Подсчитывает количество тестов в указанной директории"""
try:
# Запускаем pytest --collect-only для подсчета тестов
result = subprocess.run(
[sys.executable, '-m', 'pytest', directory, '--collect-only', '-q'],
capture_output=True,
text=True,
cwd=os.getcwd()
)
if result.returncode == 0:
# Ищем строку с количеством собранных тестов
for line in result.stdout.split('\n'):
if 'collected' in line:
# Извлекаем число из строки вида "78 collected"
parts = line.strip().split()
for part in parts:
if part.isdigit():
return int(part)
return 0
except Exception as e:
print(f"Ошибка при подсчете тестов в {directory}: {e}", file=sys.stderr)
return 0
def count_bot_tests():
"""Подсчитывает количество тестов бота"""
try:
# Переходим в директорию бота и запускаем pytest
bot_dir = os.path.join(os.getcwd(), 'bots', 'telegram-helper-bot')
result = subprocess.run(
[sys.executable, '-m', 'pytest', 'tests/', '--collect-only', '-q'],
capture_output=True,
text=True,
cwd=bot_dir
)
if result.returncode == 0:
# Ищем строку с количеством собранных тестов
for line in result.stdout.split('\n'):
if 'collected' in line:
# Извлекаем число из строки вида "201 collected"
parts = line.strip().split()
for part in parts:
if part.isdigit():
return int(part)
return 0
except Exception as e:
print(f"Ошибка при подсчете тестов бота: {e}", file=sys.stderr)
return 0
def main():
"""Основная функция"""
# Подсчитываем тесты инфраструктуры
infra_tests = count_tests_in_directory('tests/infra/')
# Подсчитываем тесты бота
bot_tests = count_bot_tests()
total_tests = infra_tests + bot_tests
# Выводим результат в формате для Makefile
print(f"{infra_tests}")
print(f"{bot_tests}")
print(f"{total_tests}")
if __name__ == '__main__':
main()