Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tikolakin committed Feb 12, 2024
1 parent 7caea07 commit 3c7bbde
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3c7bbde

Please sign in to comment.