Skip to content
Open
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
10 changes: 9 additions & 1 deletion src/pytest_bdd/gherkin_terminal_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:

rule = scenario.get("rule")
indent = " " if rule else ""
tags = [tag.lstrip("@") for tag in scenario["tags"]]
tags_text = ", ".join(tags)

if self.verbosity == 1:
self.ensure_newline()
Expand All @@ -96,6 +98,8 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
self._tw.write(" ")
self._tw.write(word, **word_markup)
self._tw.write("\n")
if tags:
self._tw.write(f"{indent} (tags: {tags_text})\n", **scenario_markup)
elif self.verbosity > 1:
self.ensure_newline()
self._tw.write(f"{scenario['feature']['keyword']}: ", **feature_markup)
Expand All @@ -114,6 +118,10 @@ 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")
if tags:
self._tw.write("\n")
self._tw.write(f"{indent} (tags: {tags_text})\n\n", **scenario_markup)
else:
self._tw.write("\n\n")

self.stats.setdefault(cat, []).append(rep)
46 changes: 46 additions & 0 deletions tests/feature/test_gherkin_terminal_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,52 @@ def test_double_verbose_mode_should_display_full_scenario_description(pytester):
result.stdout.fnmatch_lines("*When the bar is accessed")
result.stdout.fnmatch_lines("*Then world explodes")
result.stdout.fnmatch_lines("*PASSED")
assert not any("(tags:" in line for line in result.stdout.lines)


@pytest.mark.parametrize("verbosity", ["-v", "-vv"])
def test_verbose_mode_should_display_scenario_tags(pytester, verbosity):
pytester.makefile(
".feature",
test=textwrap.dedent(
"""\
Feature: Tool for network testing
@R1.1 @R1.2
Scenario: Send packages to socket
Given a service listening on a random socket
When tool sends packages to socket
Then packages are received in the service
"""
),
)
pytester.makepyfile(
textwrap.dedent(
"""\
from pytest_bdd import given, when, then, scenario


@given("a service listening on a random socket")
def _():
pass

@when("tool sends packages to socket")
def _():
pass

@then("packages are received in the service")
def _():
pass

@scenario("test.feature", "Send packages to socket")
def test_send_packages_to_socket():
pass
"""
)
)

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"])
Expand Down