From 7ea062d7d87fc4f470007cd986c7f6e1c4eb22fb Mon Sep 17 00:00:00 2001 From: tligui_y Date: Wed, 9 Jul 2025 21:32:06 +0200 Subject: [PATCH] Add json_to_md.py --- json_to_md.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 json_to_md.py diff --git a/json_to_md.py b/json_to_md.py new file mode 100644 index 000000000..aa7bbc4b6 --- /dev/null +++ b/json_to_md.py @@ -0,0 +1,56 @@ +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') \ No newline at end of file