From 3c7bbde984a6d7874db16600cf37b40ca37b60f5 Mon Sep 17 00:00:00 2001 From: Tiko Date: Mon, 12 Feb 2024 08:22:10 +0100 Subject: [PATCH] update readme --- README.md | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index aea8838..bcc521b 100644 --- a/README.md +++ b/README.md @@ -90,14 +90,29 @@ Artifacts. You would need to decide when and where you want to upload your test artifacts to cloud storage -Using pytest fixtures might be a good choice, ex.: +Upload page screenshot when test fails, using fixtures [reference](https://docs.pytest.org/en/latest/example/simple.html#making-test-result-information-available-in-fixtures) ```python +# content of conftest.py +import pytest +from typing import Dict +from pytest import StashKey, CollectReport +from playwright.sync_api import Page + +phase_report_key = StashKey[Dict[str, CollectReport]]() + +@pytest.hookimpl(wrapper=True, tryfirst=True) +def pytest_runtest_makereport(item, call): + rep = yield + item.stash.setdefault(phase_report_key, {})[rep.when] = rep + return rep + + @pytest.fixture(scope="function") -def page(context, request): - page = context.new_page() +def handle_artifacts(page: Page, request): yield - if request.node.rep_call.failed: + report = request.node.stash[phase_report_key] + if ("call" not in report) or report["setup"].failed or report["call"].failed: random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) filename = f"{random_string}.png" @@ -168,6 +183,9 @@ def test_example(): ## Change log +### 1.5.0 - Fixes artifacts in fixtures lifecycle +- Earlier, artifacts added in pytest fixtures where scipped by analyser + ### 1.4.0 - Fixes artifacts and test sync with Testomatio - Fixes artifacts uploads - Fixes test id resolution when syncing local test with Testomatio