56 lines
2.4 KiB
Python
56 lines
2.4 KiB
Python
import json
|
|
from datetime import datetime
|
|
|
|
def json_to_adaptive_md(json_path, md_path):
|
|
"""Convertit le JSON pytest en Markdown avec structure dynamique"""
|
|
with open(json_path) as f:
|
|
data = json.load(f)
|
|
|
|
with open(md_path, 'w', encoding='utf-8') as f:
|
|
# En-tête
|
|
f.write(f"# 🏗 Rapport de Tests (Générique)\n")
|
|
f.write(f"*Généré le {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}*\n\n")
|
|
|
|
# Section Summary dynamique
|
|
if 'summary' in data:
|
|
f.write("## 📋 Summary\n")
|
|
for key, value in data['summary'].items():
|
|
f.write(f"- **{key.capitalize()}:** `{value}`\n")
|
|
f.write("\n")
|
|
|
|
# Traitement hiérarchique automatique
|
|
if 'tests' in data:
|
|
current_file = None
|
|
|
|
for test in data['tests']:
|
|
# Nouveau fichier détecté
|
|
if '::' in test['nodeid'] and current_file != test['nodeid'].split('::')[0]:
|
|
current_file = test['nodeid'].split('::')[0]
|
|
f.write(f"\n## 📄 Fichier: `{current_file}`\n")
|
|
|
|
# Nom du test (sans les paramètres pour plus de clarté)
|
|
test_name = test['nodeid'].split('::')[-1].split('[')[0]
|
|
f.write(f"\n### 🧪 {test_name}\n")
|
|
|
|
# Paramètres dynamiques
|
|
if '[' in test['nodeid']:
|
|
params = test['nodeid'].split('[')[1].rstrip(']')
|
|
f.write("- **Paramètres:**\n")
|
|
for i, param in enumerate(params.split('-'), 1):
|
|
f.write(f" - Param {i}: `{param}`\n")
|
|
|
|
# Métadonnées communes
|
|
f.write(f"- **Statut:** {'✅ Passed' if test['outcome'] == 'passed' else '❌ Failed'}\n")
|
|
if 'duration' in test:
|
|
f.write(f"- **Durée:** {test['duration']:.3f}s\n")
|
|
|
|
# Détails spécifiques au résultat
|
|
if test['outcome'] != 'passed':
|
|
for key in ['message', 'longrepr', 'crash']:
|
|
if key in test:
|
|
f.write(f"\n**{key.capitalize()}:**\n```\n{str(test[key])}\n```\n")
|
|
|
|
f.write("\n" + "-"*50 + "\n")
|
|
|
|
# Utilisation
|
|
json_to_adaptive_md('pytest-report.json', 'GENERIC-REPORT.md') |