Skip to content

Commit

Permalink
Merge pull request #467 from radish-bdd/bugfix/tags-in-scenario-outline
Browse files Browse the repository at this point in the history
Bugfix: tags in scenario outline and loop scenarios
  • Loading branch information
fliiiix authored Nov 5, 2023
2 parents 4688b59 + 8e40809 commit 4eca04a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 3 deletions.
4 changes: 3 additions & 1 deletion radish/examplescenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class ExampleScenario(Scenario):
"""

def __init__(self, id, keyword, sentence, path, line, parent, example, background=None):
super(ExampleScenario, self).__init__(id, keyword, sentence, path, line, parent, background=background)
super(ExampleScenario, self).__init__(
id, keyword, sentence, path, line, parent, parent.tags, background=background
)
self.example = example

def has_to_run(self, scenario_choice):
Expand Down
2 changes: 1 addition & 1 deletion radish/extensions/bdd_xml_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
from lxml import etree
except ImportError:
raise RadishError(
'if you want to use the BDD xml writer you have to install extra packages: "pip install radish-bdd[bdd-xml]"'
'if you want to use the BDD xml writer you have to install extra packages: "pip install radish-bdd[bddxml]"'
)

after.all(self.generate_bdd_xml)
Expand Down
4 changes: 3 additions & 1 deletion radish/iterationscenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class IterationScenario(Scenario):
"""

def __init__(self, id, keyword, sentence, path, line, parent, iteration, background=None):
super(IterationScenario, self).__init__(id, keyword, sentence, path, line, parent, background=background)
super(IterationScenario, self).__init__(
id, keyword, sentence, path, line, parent, parent.tags, background=background
)
self.iteration = iteration

def has_to_run(self, scenario_choice):
Expand Down
8 changes: 8 additions & 0 deletions tests/features/scenario-loop-tag.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Support Scenario Loop
Radish shall support Scenario Loops.

@arbitrary_tag
Scenario Loop 2: This is a looped Scenario
Given I have an instable function
When I execute it
Then I expect it to pass
15 changes: 15 additions & 0 deletions tests/features/scenario-outline-tag.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: Support Scenario Outlines
Radish shall support parsing
of Scenario Outlines with valid Examples

@arbitrary_tag
Scenario Outline: A Scenario Outline
Given I have the number <x>
And I have the number <y>
When I add them up
Then I expect the sum to be <z>

Examples:
| x | y | z |
| 1 | 2 | 3 |
| 4 | 5 | 9 |
31 changes: 31 additions & 0 deletions tests/functional/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,24 @@ def test_parse_feature_with_scenario_outline(parser):
assert feature.scenarios[0].scenarios[1].steps[3].sentence == "Then I expect the sum to be 9"


@pytest.mark.parametrize("parser", [("scenario-outline-tag",)], indirect=["parser"])
def test_tags_are_propagated_to_example_scenarios(parser):
"""
Test parsing a Feature with a simple Scenario Outline with tags
"""
# when
feature = parser.parse()

# then
assert len(feature.scenarios) == 1
assert isinstance(feature.scenarios[0], ScenarioOutline)
assert len(feature.scenarios[0].scenarios) == 2

# then - expect tags are set from parent for each scenario
assert feature.scenarios[0].scenarios[0].tags == [Tag("arbitrary_tag")]
assert feature.scenarios[0].scenarios[1].tags == [Tag("arbitrary_tag")]


@pytest.mark.parametrize("parser", [("scenario-outline-step-text",)], indirect=["parser"])
def test_parse_scenario_outline_with_step_text(parser):
"""
Expand Down Expand Up @@ -347,6 +365,19 @@ def test_parse_feature_with_scenario_loop(parser):
assert feature.scenarios[0].scenarios[1].steps[2].sentence == "Then I expect it to pass"


@pytest.mark.parametrize("parser", [("scenario-loop-tag",)], indirect=["parser"])
def test_tags_are_propagated_to_iterationscenario_scenarios(parser):
"""
Test parsing a Feature with a simple Scenario Loop with tags
"""
# when
feature = parser.parse()

# then - expect tags are set from parent for each scenario
assert feature.scenarios[0].scenarios[0].tags == [Tag("arbitrary_tag")]
assert feature.scenarios[0].scenarios[1].tags == [Tag("arbitrary_tag")]


@pytest.mark.parametrize("parser", [("step-tabular-data",)], indirect=["parser"])
def test_parse_step_tabular_data(parser):
"""
Expand Down

0 comments on commit 4eca04a

Please sign in to comment.