diff --git a/tests/conftest.py b/tests/conftest.py index ba85b41..1c5cf6e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -108,4 +108,26 @@ def role_page(page: Page, request): role = _get_role(request) _login(page, role) yield page - page.context.clear_cookies() \ No newline at end of file + page.context.clear_cookies() + + +# --------------------------------------------------------------------------- +# Хук для отображения читаемых имён шагов в pytest-html отчёте +# --------------------------------------------------------------------------- + +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_makereport(item, call): + """ + Заменяет технический путь к тесту в колонке Test отчёта pytest-html + на docstring метода (например, 'Шаг 1: Открыть главную страницу'). + + Если docstring отсутствует — оставляет оригинальный nodeid. + """ + outcome = yield + report = outcome.get_result() + + # Берём docstring тестовой функции + doc = getattr(item.function, "__doc__", None) + if doc: + description = doc.strip().splitlines()[0] # только первая строка + report.nodeid = description \ No newline at end of file