From f925d15c5d09e698e31ebfa2e24824dd7c359956 Mon Sep 17 00:00:00 2001 From: tligui_y Date: Mon, 14 Jul 2025 16:48:40 +0200 Subject: [PATCH] Update json_to_md.py --- json_to_md.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/json_to_md.py b/json_to_md.py index a29a4348..15f4bdd4 100644 --- a/json_to_md.py +++ b/json_to_md.py @@ -237,6 +237,42 @@ def json_to_md_nested(json_path, md_path, allure_dir=None): f.write("\n\n") +def check_keyboard_interrupt_and_prepend_warning(log_path, md_path): + interrupt_signature = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! KeyboardInterrupt !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + interrupt_file_line = None + + with open(log_path, "r") as f: + lines = f.readlines() + for i, line in enumerate(lines): + if interrupt_signature in line: + # 👇 On récupère la ligne juste après + if i + 1 < len(lines): + candidate = lines[i + 1].strip() + if candidate.endswith("KeyboardInterrupt") and ".py" in candidate: + interrupt_file_line = candidate + break + + if interrupt_file_line: + # Lire le contenu existant du report + with open(md_path, "r") as f: + original = f.read() + + # Fabriquer le header d’avertissement + warning = ( + "⚠️ **Tests interrupted by `KeyboardInterrupt`**\n\n" + f"> Source: `{interrupt_file_line}`\n\n" + "---\n\n" + ) + + # Réécrire le fichier avec l’alerte en haut + with open(md_path, "w") as f: + f.write(warning + original) + + print("⚠️ KeyboardInterrupt detected — warning added to markdown report.") + else: + print("✅ No KeyboardInterrupt detected.") + + def main(): parser = argparse.ArgumentParser(description="Convert JSON test results to Markdown.") parser.add_argument("--input", required=True, help="Path to pytest JSON file")