Coverage for pytest_beehave / steps_display.py: 36%

14 statements  

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

1"""Terminal steps display — prints BDD steps under each test name.""" 

2 

3from __future__ import annotations 

4 

5import pytest 

6 

7 

8class StepsReporter: 

9 """Prints BDD steps to the terminal when --beehave-verbose is active.""" 

10 

11 def __init__(self, config: pytest.Config) -> None: 

12 """Store pytest config for terminal writer access.""" 

13 self._config = config 

14 

15 def pytest_runtest_logreport( 

16 self, 

17 report: pytest.TestReport, 

18 ) -> None: 

19 """Print steps after each test call phase report.""" 

20 if report.when != "call" and not (report.when == "setup" and report.skipped): 

21 return 

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

23 if not steps: 

24 return 

25 writer = self._config.get_terminal_writer() 

26 indented = "\n".join(f" {line}" for line in steps.splitlines()) 

27 writer.write(f"\n{indented}\n")