chore: use uuid in screenshot name instead of timestamp to make the filename smaller
This commit is contained in:
parent
e1bb235b4e
commit
9662c974a0
|
@ -4,6 +4,7 @@ from datetime import datetime
|
||||||
import os
|
import os
|
||||||
import allure
|
import allure
|
||||||
import pytest
|
import pytest
|
||||||
|
import shortuuid
|
||||||
from PIL import ImageGrab
|
from PIL import ImageGrab
|
||||||
|
|
||||||
import configs
|
import configs
|
||||||
|
@ -61,10 +62,13 @@ def pytest_exception_interact(node):
|
||||||
test_path, test_name, test_params = generate_test_info(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: SystemPath = configs.testpath.RUN / test_path / test_name / test_params
|
||||||
node_dir.mkdir(parents=True, exist_ok=True)
|
node_dir.mkdir(parents=True, exist_ok=True)
|
||||||
screenshot = node_dir / f'screenshot_{datetime.today().strftime("%Y-%m-%d %H-%M-%S")}.png'
|
screenshot = node_dir / f'screenshot_{shortuuid.ShortUUID().random(length=10)}.png'
|
||||||
ImageGrab.grab(xdisplay=configs.system.DISPLAY if get_platform() == "Linux" else None).save(screenshot)
|
try:
|
||||||
allure.attach(
|
ImageGrab.grab(xdisplay=configs.system.DISPLAY if get_platform() == "Linux" else None).save(screenshot)
|
||||||
name='Screenshot on fail',
|
allure.attach(
|
||||||
body=screenshot.read_bytes(),
|
name='Screenshot on fail',
|
||||||
attachment_type=allure.attachment_type.PNG
|
body=screenshot.read_bytes(),
|
||||||
)
|
attachment_type=allure.attachment_type.PNG
|
||||||
|
)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Screenshot was not generated or saved")
|
||||||
|
|
Loading…
Reference in New Issue