From 9662c974a023cdf19670c07dfbfddecb44c46a3a Mon Sep 17 00:00:00 2001 From: Anastasiya Date: Mon, 8 Jul 2024 13:26:05 +0300 Subject: [PATCH] chore: use uuid in screenshot name instead of timestamp to make the filename smaller --- test/e2e/conftest.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/e2e/conftest.py b/test/e2e/conftest.py index 323be2de3a..731579bbef 100644 --- a/test/e2e/conftest.py +++ b/test/e2e/conftest.py @@ -4,6 +4,7 @@ from datetime import datetime import os import allure import pytest +import shortuuid from PIL import ImageGrab import configs @@ -61,10 +62,13 @@ def pytest_exception_interact(node): test_path, test_name, test_params = generate_test_info(node) node_dir: SystemPath = configs.testpath.RUN / test_path / test_name / test_params node_dir.mkdir(parents=True, exist_ok=True) - screenshot = node_dir / f'screenshot_{datetime.today().strftime("%Y-%m-%d %H-%M-%S")}.png' - ImageGrab.grab(xdisplay=configs.system.DISPLAY if get_platform() == "Linux" else None).save(screenshot) - allure.attach( - name='Screenshot on fail', - body=screenshot.read_bytes(), - attachment_type=allure.attachment_type.PNG - ) + screenshot = node_dir / f'screenshot_{shortuuid.ShortUUID().random(length=10)}.png' + try: + ImageGrab.grab(xdisplay=configs.system.DISPLAY if get_platform() == "Linux" else None).save(screenshot) + allure.attach( + name='Screenshot on fail', + body=screenshot.read_bytes(), + attachment_type=allure.attachment_type.PNG + ) + except FileNotFoundError: + print("Screenshot was not generated or saved")