Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Unreleased

Added
+++++
* Gherkin terminal reporter output now includes scenario tags in verbose modes. `#476 <https://github.com/pytest-dev/pytest-bdd/issues/476>`_

Changed
+++++++
Expand Down
9 changes: 8 additions & 1 deletion src/pytest_bdd/gherkin_terminal_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def __init__(self, config: Config) -> None:
super().__init__(config)
self.current_rule: str | None = None

def _write_tags(self, tags: list[str], indent: str) -> None:
if tags:
self._tw.write(f"{indent} (tags: {', '.join(tags)})\n")

def pytest_runtest_logreport(self, report: TestReport) -> None:
rep = report
res = self.config.hook.pytest_report_teststatus(report=rep, config=self.config)
Expand Down Expand Up @@ -96,6 +100,7 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
self._tw.write(" ")
self._tw.write(word, **word_markup)
self._tw.write("\n")
self._write_tags(scenario["tags"], indent)
elif self.verbosity > 1:
self.ensure_newline()
self._tw.write(f"{scenario['feature']['keyword']}: ", **feature_markup)
Expand All @@ -114,6 +119,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
for step in scenario["steps"]:
self._tw.write(f"{indent} {step['keyword']} {step['name']}\n", **scenario_markup)
self._tw.write(f"{indent} {word}", **word_markup)
self._tw.write("\n\n")
self._tw.write("\n")
self._write_tags(scenario["tags"], indent)
self._tw.write("\n")

self.stats.setdefault(cat, []).append(rep)
26 changes: 26 additions & 0 deletions tests/feature/test_gherkin_terminal_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
Then world explodes
"""

FEATURE_WITH_TAGS = """\
Feature: Gherkin terminal output feature
@R1.1 @R1.2
Scenario: Scenario example 1
Given there is a bar
When the bar is accessed
Then world explodes
"""

TEST = """\
from pytest_bdd import given, when, then, scenario

Expand Down Expand Up @@ -97,6 +106,23 @@ def test_double_verbose_mode_should_display_full_scenario_description(pytester):
result.stdout.fnmatch_lines("*PASSED")


@pytest.mark.parametrize("verbosity", ["-v", "-vv"])
def test_verbose_modes_display_scenario_tags(pytester, verbosity):
pytester.makeini("""\
[pytest]
markers =
R1.1
R1.2
""")
pytester.makefile(".feature", test=FEATURE_WITH_TAGS)
pytester.makepyfile(TEST)

result = pytester.runpytest("--gherkin-terminal-reporter", verbosity)

result.assert_outcomes(passed=1, failed=0)
result.stdout.fnmatch_lines("*(tags: R1.1, R1.2)")


@pytest.mark.parametrize("verbosity", ["", "-v", "-vv"])
def test_error_message_for_missing_steps(pytester, verbosity):
pytester.makefile(".feature", test=FEATURE)
Expand Down