pytest_beehave.steps_reporter
Terminal steps reporter for pytest-beehave.
1"""Terminal steps reporter for pytest-beehave.""" 2 3from __future__ import annotations 4 5import sys 6 7import pytest 8 9 10class StepsReporter: 11 """Prints BDD step docstrings to the terminal for tests/features/ tests.""" 12 13 def __init__(self, config: pytest.Config) -> None: 14 """Initialise the reporter. 15 16 Args: 17 config: The pytest Config object. 18 """ 19 self._config = config 20 21 def pytest_runtest_logreport(self, report: pytest.TestReport) -> None: 22 """Print steps docstring after each test call phase report. 23 24 Args: 25 report: The test report for the current phase. 26 """ 27 if report.when != "call" and not (report.when == "setup" and report.skipped): 28 return 29 config = self._config 30 option = config.option 31 verbose = option.verbose 32 if verbose < 1: 33 return 34 nodeid = report.nodeid 35 if "tests/features/" not in nodeid: 36 return 37 docstring = getattr(report, "_beehave_docstring", "") 38 if not docstring: 39 return 40 self._write_steps(docstring.strip()) 41 42 def _write_steps(self, steps: str) -> None: 43 """Write the steps string to the terminal or stdout fallback. 44 45 Args: 46 steps: The stripped docstring content to write. 47 """ 48 try: 49 config = self._config 50 writer = config.get_terminal_writer() 51 writer.write("\n" + steps + "\n") 52 except (AssertionError, AttributeError): 53 sys.stdout.write("\n" + steps + "\n") 54 sys.stdout.flush()
class
StepsReporter:
11class StepsReporter: 12 """Prints BDD step docstrings to the terminal for tests/features/ tests.""" 13 14 def __init__(self, config: pytest.Config) -> None: 15 """Initialise the reporter. 16 17 Args: 18 config: The pytest Config object. 19 """ 20 self._config = config 21 22 def pytest_runtest_logreport(self, report: pytest.TestReport) -> None: 23 """Print steps docstring after each test call phase report. 24 25 Args: 26 report: The test report for the current phase. 27 """ 28 if report.when != "call" and not (report.when == "setup" and report.skipped): 29 return 30 config = self._config 31 option = config.option 32 verbose = option.verbose 33 if verbose < 1: 34 return 35 nodeid = report.nodeid 36 if "tests/features/" not in nodeid: 37 return 38 docstring = getattr(report, "_beehave_docstring", "") 39 if not docstring: 40 return 41 self._write_steps(docstring.strip()) 42 43 def _write_steps(self, steps: str) -> None: 44 """Write the steps string to the terminal or stdout fallback. 45 46 Args: 47 steps: The stripped docstring content to write. 48 """ 49 try: 50 config = self._config 51 writer = config.get_terminal_writer() 52 writer.write("\n" + steps + "\n") 53 except (AssertionError, AttributeError): 54 sys.stdout.write("\n" + steps + "\n") 55 sys.stdout.flush()
Prints BDD step docstrings to the terminal for tests/features/ tests.
StepsReporter(config: _pytest.config.Config)
14 def __init__(self, config: pytest.Config) -> None: 15 """Initialise the reporter. 16 17 Args: 18 config: The pytest Config object. 19 """ 20 self._config = config
Initialise the reporter.
Args: config: The pytest Config object.
def
pytest_runtest_logreport(self, report: _pytest.reports.TestReport) -> None:
22 def pytest_runtest_logreport(self, report: pytest.TestReport) -> None: 23 """Print steps docstring after each test call phase report. 24 25 Args: 26 report: The test report for the current phase. 27 """ 28 if report.when != "call" and not (report.when == "setup" and report.skipped): 29 return 30 config = self._config 31 option = config.option 32 verbose = option.verbose 33 if verbose < 1: 34 return 35 nodeid = report.nodeid 36 if "tests/features/" not in nodeid: 37 return 38 docstring = getattr(report, "_beehave_docstring", "") 39 if not docstring: 40 return 41 self._write_steps(docstring.strip())
Print steps docstring after each test call phase report.
Args: report: The test report for the current phase.