Pytest
pip install tracera-pytest
Requires Python ≥ 3.11 and pytest ≥ 8 (see Autotest adapters). tracera-pytest on PyPI.
Environment variables, run mode, and retries: Autotest adapters.
Retry Env key: PYTEST_RETRY.
Bind testCaseId and autotestName
Import stock pytest APIs as usual, and tracera and id from tracera_pytest.
At declaration (preferred — bind runs even if the body skips early):
import pytest
from tracera_pytest import id as tracera_id
@tracera_id(42, "e2e/login")
def test_login():
assert True
Inside the test (optional if @tracera.id already binds the case):
from tracera_pytest import tracera
def test_login():
tracera.test_case(42, "e2e/login")
assert True
Skip
Use stock pytest skip (pytest.skip, @pytest.mark.skip, …). The skip reason is added to the result as comment.
import os
import pytest
from tracera_pytest import id as tracera_id
@tracera_id(42, "e2e/login")
def test_login():
if not os.environ.get("READY"):
pytest.skip("env not ready")
Steps
Use tracera.step(title, body), @tracera.step("…"), with tracera.step("…"):, or async with tracera.step("…"): (also @tracera.step / await tracera.step(…) on async def). In the @tracera.step("add {item}") decorator, {item} is substituted from the function’s item argument. Steps inside function-scoped fixtures go to the result’s Setup / Teardown; steps inside the test go to the result’s Test section. Suite-level hooks are not reported.
import pytest
from tracera_pytest import tracera
@pytest.fixture(autouse=True)
def open_shop():
with tracera.step("open shop"):
pass
yield
with tracera.step("cleanup"):
pass
@tracera.step("add {item}")
def add_to_cart(item: str):
pass
def test_checkout():
tracera.test_case(10, "e2e/checkout")
add_to_cart("sku-1") # → step "add sku-1"
Comments, errors, and attachments
Comments, errors, and attachments: Autotest adapters.
from tracera_pytest import tracera
def test_login():
tracera.test_case(42, "e2e/login")
tracera.comment("result-level note")
tracera.error("result-level error text")
with tracera.step("open login"):
tracera.comment("landed on login")
tracera.attachment(
file_name="suite-log.txt",
mime_type="text/plain",
data=b"finished login flow",
)
Parameterized tests
The second argument in the @tracera.id decorator is the autotest name. You can put {arg_name} / {param_id} placeholders in it; each {arg_name} must match a test function argument, and every @pytest.mark.parametrize row fills them from that row ({param_id} is the parameter id when pytest provides one). In the example below you get two results for case 42, with autotest names login as ok and login as sso:
import pytest
from tracera_pytest import id as tracera_id
@tracera_id(42, "login as {login}")
@pytest.mark.parametrize("login", ["ok", "sso"])
def test_login(login):
assert login
Or bind inside the test when the case id also varies:
import pytest
from tracera_pytest import tracera
@pytest.mark.parametrize(
"case_id,name",
[
(42, "e2e/login-ok"),
(43, "e2e/login-sso"),
],
)
def test_login_row(case_id, name):
tracera.test_case(case_id, name)
with tracera.step("open"):
pass