Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let gherkin-terminal-reporter-expanded enable gherkin output #275

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions pytest_bdd/cucumber_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def add_options(parser):
"--cucumberjson-expanded",
"--cucumber-json-expanded",
action="store_true",
dest="expand",
dest="cucumber_json_expanded",
default=False,
help="expand scenario outlines into scenarios and fill in the step names",
)
Expand All @@ -42,7 +42,7 @@ def configure(config):
cucumber_json_path = config.option.cucumber_json_path
# prevent opening json log on slave nodes (xdist)
if cucumber_json_path and not hasattr(config, "slaveinput"):
config._bddcucumberjson = LogBDDCucumberJSON(cucumber_json_path, expand=config.option.expand)
config._bddcucumberjson = LogBDDCucumberJSON(cucumber_json_path, expand=config.option.cucumber_json_expanded)
config.pluginmanager.register(config._bddcucumberjson)


Expand Down
8 changes: 4 additions & 4 deletions pytest_bdd/gherkin_terminal_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def add_options(parser):
group._addoption(
"--gherkin-terminal-reporter-expanded",
action="store_true",
dest="expand",
dest="gherkin_expanded",
default=False,
help="expand scenario outlines into scenarios and fill in the step names",
help="enable gherkin output, expand scenario outlines into scenarios and fill in the step names",
)


def configure(config):
if config.option.gherkin_terminal_reporter:
if config.option.gherkin_terminal_reporter or config.option.gherkin_expanded:
# Get the standard terminal reporter plugin and replace it with our
current_reporter = config.pluginmanager.getplugin('terminalreporter')
if current_reporter.__class__ != TerminalReporter:
Expand Down Expand Up @@ -102,7 +102,7 @@ def pytest_runtest_logreport(self, report):
self._tw.write(report.scenario['name'], **scenario_markup)
self._tw.write('\n')
for step in report.scenario['steps']:
if self.config.option.expand:
if self.config.option.gherkin_expanded:
step_name = self._format_step_name(step['name'], **report.scenario['example_kwargs'])
else:
step_name = step['name']
Expand Down
7 changes: 6 additions & 1 deletion tests/feature/gherkin_terminal_reporter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,10 @@ Feature: Gherkin terminal reporter

Scenario: Should step parameters be replaced by their values
Given there is gherkin scenario outline implemented
When tests are run with step expanded mode
When tests are run with step expanded option
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make it clearer to have a step like "when tests are run with --gherkin-terminal-reporter-expanded". What do you think?

Then output must contain parameters values

Scenario: Should step parameters be replaced by their values also when used together with gherkin reporter option
Given there is gherkin scenario outline implemented
When tests are run with step expanded and gherkin reporter options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make it clearer to have a step like "when tests are run with --gherkin-terminal-reporter --gherkin-terminal-reporter-expanded".
Also, these 2 tests are basically the same, the only thing that differ is the options. Should we instead parametrize the options in the scenario outline and have 1 scenario definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved both tests into parameterized scenario :)

Then output must contain parameters values
19 changes: 17 additions & 2 deletions tests/feature/test_gherkin_terminal_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def test_Should_step_parameters_be_replaced_by_their_values():
pass


@scenario('gherkin_terminal_reporter.feature',
'Should step parameters be replaced by their values also when used together with gherkin reporter option')
def test_Should_step_parameters_be_replaced_by_their_values_also_when_used_together_with_gherkin_reporter_option():
pass


@pytest.fixture(params=[0, 1, 2],
ids=['compact mode', 'line per test', 'verbose'])
def verbosity_mode(request):
Expand Down Expand Up @@ -185,8 +191,17 @@ def tests_are_run_with_very_verbose_mode(testdir, test_execution):
test_execution['gherkin'] = testdir.runpytest('--gherkin-terminal-reporter', '-vv')


@when("tests are run with step expanded mode")
def tests_are_run_with_step_expanded_mode(testdir, test_execution):
@when("tests are run with step expanded option")
def tests_are_run_with_step_expanded_option(testdir, test_execution):
test_execution['regular'] = testdir.runpytest('-vv')
test_execution['gherkin'] = testdir.runpytest(
'--gherkin-terminal-reporter-expanded',
'-vv',
)


@when("tests are run with step expanded and gherkin reporter options")
def tests_are_run_with_step_expanded_and_gherkin_reporter_options(testdir, test_execution):
test_execution['regular'] = testdir.runpytest('-vv')
test_execution['gherkin'] = testdir.runpytest(
'--gherkin-terminal-reporter',
Expand Down