From ab8f068a5e07d75ddd41663e8377719a75235364 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 22 Nov 2023 23:25:16 +0100 Subject: [PATCH] traceback of failed test gets saved via hook --- src/conftest.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/conftest.py b/src/conftest.py index 7e714ee..f8185d4 100644 --- a/src/conftest.py +++ b/src/conftest.py @@ -5,12 +5,12 @@ # sys.path. It is thus good practise for projects to either put conftest.py under # a package scope or to never import anything from a conftest.py file. -import os.path from pathlib import Path import pytest from dirmanager import DirManager from dotenv import dotenv_values +from icecream import ic from playwright.sync_api import BrowserContext pytest_plugins = [ @@ -79,8 +79,12 @@ def pytest_runtest_makereport(item, call): # we only look at actual failing test calls, not setup/teardown if rep.when == "call" and rep.failed: - mode = "a" if os.path.exists("failures") else "w" - with open("failures", mode) as f: + # saves traceback as .txt for failed test + filename = f"failed-{item.nodeid}.txt" + filename = filename.replace("/", "-") + filename = filename.replace("::", "-") + filepath = item.funcargs["RESULTS"] / filename + with open(filepath, "a") as f: f.write(rep.longreprtext + "\n")