Skip to content

Commit

Permalink
Allow for scenario descriptions to be present
Browse files Browse the repository at this point in the history
fixes #311

This treats scenario descriptions the same way it does
feature descriptions.
  • Loading branch information
rbcasperson committed Jul 25, 2019
1 parent a043aeb commit 64d2d77
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion pytest_bdd/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
STEP_PARAM_RE = re.compile(r"\<(.+?)\>")
COMMENT_RE = re.compile(r'(^|(?<=\s))#')

TYPES_WITH_DESCRIPTIONS = [types.FEATURE, types.SCENARIO, types.SCENARIO_OUTLINE]


def get_step_type(line):
"""Detect step type by the beginning of the line.
Expand Down Expand Up @@ -291,7 +293,8 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True):
multiline_step = False
stripped_line = line.strip()
clean_line = strip_comments(line)
if not clean_line and (not prev_mode or prev_mode not in types.FEATURE):
if not clean_line and (not prev_mode or prev_mode not in TYPES_WITH_DESCRIPTIONS):
# Blank lines are included in feature and scenario descriptions
continue
mode = get_step_type(clean_line) or mode

Expand Down Expand Up @@ -340,6 +343,13 @@ def __init__(self, basedir, filename, encoding="utf-8", strict_gherkin=True):
# Remove Feature, Given, When, Then, And
keyword, parsed_line = parse_line(clean_line)
if mode in [types.SCENARIO, types.SCENARIO_OUTLINE]:
# Lines between the scenario declaration
# and the scenario's first step line
# are considered part of the scenario description.
if scenario and not keyword:
scenario.add_description_line(parsed_line)
continue

tags = get_tags(prev_line)
self.scenarios[parsed_line] = scenario = Scenario(self, parsed_line, line_number, tags=tags)
elif mode == types.BACKGROUND:
Expand Down Expand Up @@ -435,6 +445,7 @@ def __init__(self, feature, name, line_number, example_converters=None, tags=Non
self.tags = tags or set()
self.failed = False
self.test_function = None
self._description_lines = []

def add_step(self, step):
"""Add step to the scenario.
Expand All @@ -456,6 +467,22 @@ def steps(self):
result.extend(self._steps)
return result

def add_description_line(self, description_line):
"""Add a description line to the scenario.
:param str description_line:
"""
self._description_lines.append(description_line)

@property
def description(self):
"""Get the scenario's description.
:return: The scenario description
"""
return u"\n".join(self._description_lines).strip()


@property
def params(self):
"""Get parameter names.
Expand Down

0 comments on commit 64d2d77

Please sign in to comment.