From 055c6688b0bccd56ac78a09ec708e693e0e708d0 Mon Sep 17 00:00:00 2001 From: Milosz Sliwinski Date: Sat, 24 Nov 2018 11:06:52 +0100 Subject: [PATCH 1/2] Let gherkin-terminal-reporter-expanded enable gherkin output --- pytest_bdd/cucumber_json.py | 4 ++-- pytest_bdd/gherkin_terminal_reporter.py | 8 ++++---- .../feature/gherkin_terminal_reporter.feature | 7 ++++++- .../feature/test_gherkin_terminal_reporter.py | 19 +++++++++++++++++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pytest_bdd/cucumber_json.py b/pytest_bdd/cucumber_json.py index 71b9feab..41b8dc4c 100644 --- a/pytest_bdd/cucumber_json.py +++ b/pytest_bdd/cucumber_json.py @@ -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", ) @@ -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) diff --git a/pytest_bdd/gherkin_terminal_reporter.py b/pytest_bdd/gherkin_terminal_reporter.py index f846084a..e3378767 100644 --- a/pytest_bdd/gherkin_terminal_reporter.py +++ b/pytest_bdd/gherkin_terminal_reporter.py @@ -21,14 +21,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: @@ -100,7 +100,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'] diff --git a/tests/feature/gherkin_terminal_reporter.feature b/tests/feature/gherkin_terminal_reporter.feature index 4f8d0939..95f2ceb7 100644 --- a/tests/feature/gherkin_terminal_reporter.feature +++ b/tests/feature/gherkin_terminal_reporter.feature @@ -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 + 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 Then output must contain parameters values diff --git a/tests/feature/test_gherkin_terminal_reporter.py b/tests/feature/test_gherkin_terminal_reporter.py index 1fab6598..f2d989ce 100644 --- a/tests/feature/test_gherkin_terminal_reporter.py +++ b/tests/feature/test_gherkin_terminal_reporter.py @@ -60,6 +60,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): @@ -184,8 +190,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', From 465764b962c4165be5574160bd6eceb1f0a071e1 Mon Sep 17 00:00:00 2001 From: Milosz Sliwinski Date: Sat, 23 Feb 2019 14:10:35 +0100 Subject: [PATCH 2/2] --gherkin-terminal-reporter-expanded option tests simplified --- .../feature/gherkin_terminal_reporter.feature | 12 +++++----- .../feature/test_gherkin_terminal_reporter.py | 24 ++++--------------- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/tests/feature/gherkin_terminal_reporter.feature b/tests/feature/gherkin_terminal_reporter.feature index 95f2ceb7..3f933f1b 100644 --- a/tests/feature/gherkin_terminal_reporter.feature +++ b/tests/feature/gherkin_terminal_reporter.feature @@ -41,12 +41,12 @@ Feature: Gherkin terminal reporter When tests are run with --showlocals Then error traceback contains local variable descriptions - Scenario: Should step parameters be replaced by their values + Scenario Outline: Should step parameters be replaced by their values Given there is gherkin scenario outline implemented - When tests are run with step expanded option + When tests are run with 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 - Then output must contain parameters values + Examples: + | gherkin_options | + | --gherkin-terminal-reporter-expanded | + | --gherkin-terminal-reporter --gherkin-terminal-reporter-expanded | diff --git a/tests/feature/test_gherkin_terminal_reporter.py b/tests/feature/test_gherkin_terminal_reporter.py index a90b0724..81a1438c 100644 --- a/tests/feature/test_gherkin_terminal_reporter.py +++ b/tests/feature/test_gherkin_terminal_reporter.py @@ -61,12 +61,6 @@ 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): @@ -191,22 +185,12 @@ 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 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): +@when("tests are run with ") +def tests_are_run_with_step_expanded_option(testdir, test_execution, gherkin_options): test_execution['regular'] = testdir.runpytest('-vv') + options = gherkin_options + ' -vv' test_execution['gherkin'] = testdir.runpytest( - '--gherkin-terminal-reporter', - '--gherkin-terminal-reporter-expanded', - '-vv', + *options.split() )