Hooks
pytest-embedded exposes pytest hook specifications (registered via pytest_addhooks) for customizing test execution and reporting in conftest.py or downstream plugins.
pytest_custom_unity_case_name
@pytest.hookspec(firstresult=True)
def pytest_custom_unity_case_name(item: pytest.Item, case_name: str) -> str | None: ...
Customize the reported name of each Unity sub-case parsed from DUT output.
Behavior
Resolution:
firstresult=True— the first hook implementation returning a non-Nonestring wins. ReturningNone(or providing no implementation) keeps the original Unitycase_name.Invocation timing: Called during
pytest_runtest_makereportwhencall.when == "call".DUT coverage: Runs over
dut.testsuite.testcasesfor all DUTs attached to the item — singledutfixture, multi-DUT tuple, and any DUTs created viaDutFactory.JUnit XML: Mutates
case.nameand its XMLnameattribute in place so merged JUnit reports (--junitxml) use the finalized name.Item stash: Publishes all finalized cases to
item.stash[pytest_embedded.unity.UnityCasesStashKey]aslist[UnityCase].UnityCaseis aNamedTuple(name: str, result: str).resultmaps Unity outcomes asPASS→"passed",FAIL→"failed",IGNORE→"skipped".
Example
import pytest
from pytest_embedded.unity import UnityCasesStashKey
def pytest_custom_unity_case_name(item: pytest.Item, case_name: str) -> str:
return f"{item.name}::{case_name}"
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo) -> None:
yield # wait for pytest-embedded to populate the item stash
if call.when == "call":
unity_cases = item.stash.get(UnityCasesStashKey, [])
for case in unity_cases:
print(case.name, case.result)