Coverage for pytest_beehave / html_column.py: 67%

12 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-20 20:14 +0000

1"""HTML column — adds a Scenario column to pytest-html reports.""" 

2 

3from __future__ import annotations 

4 

5import html 

6 

7import pytest 

8 

9_SCENARIO_HEADER = ( 

10 '<th class="sortable scenario" data-column-type="scenario">Scenario</th>' 

11) 

12_SCENARIO_CELL = ( 

13 '<td class="col-scenario" style="white-space: pre-wrap;">{content}</td>' 

14) 

15 

16 

17class HtmlStepsPlugin: 

18 """Adds a Scenario column with BDD steps to pytest-html reports.""" 

19 

20 def pytest_html_results_table_header( 

21 self, 

22 cells: list[object], 

23 ) -> None: 

24 """Insert the Scenario column header after Test.""" 

25 cells.insert(2, _SCENARIO_HEADER) 

26 

27 def pytest_html_results_table_row( 

28 self, 

29 report: pytest.TestReport, 

30 cells: list[object], 

31 ) -> None: 

32 """Insert the Scenario cell for each test row.""" 

33 steps = getattr(report, "_beehave_steps", None) 

34 content = html.escape(steps) if steps else "" 

35 cells.insert(2, _SCENARIO_CELL.format(content=content))