Skip to content

Commit a10b5a4

Browse files
authored
Merge pull request #722 from pytest-dev/do-not-strip-comments-from-step-names
Do not strip comments from step names
2 parents 3402450 + 43d062b commit a10b5a4

File tree

7 files changed

+16
-27
lines changed

7 files changed

+16
-27
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
Unreleased
55
----------
66
- Dropped support for python 3.8. Supported python versions: 3.9, 3.10, 3.11, 3.12, 3.13.
7+
- Text after the `#` character is no longer stripped from the Scenario and Feature name.
78

89
8.0.0b2
910
----------
@@ -21,6 +22,7 @@ Unreleased
2122
- All feature files must now use the keyword `Feature:` to be considered valid.
2223
- Tags can no longer have spaces (e.g. "@tag one" and "@tag two" are no longer valid).
2324
- Tags can now be on multiple lines (stacked)
25+
- Text after the `#` character is no longer stripped from the Step name.
2426

2527
7.3.0
2628
----------

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Note that pytest-splinter_ is used to get the browser fixture.
5656
And I press the publish button
5757
5858
Then I should not see the error message
59-
And the article should be published # Note: will query the database
59+
And the article should be published
6060
6161
Note that only one feature is allowed per feature file.
6262

src/pytest_bdd/parser.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@
2020
from .types import STEP_TYPES
2121

2222
STEP_PARAM_RE = re.compile(r"<(.+?)>")
23-
COMMENT_RE = re.compile(r"(^|(?<=\s))#")
24-
25-
26-
def strip_comments(line: str) -> str:
27-
"""Remove comments from a line of text.
28-
29-
Args:
30-
line (str): The line of text from which to remove comments.
31-
32-
Returns:
33-
str: The line of text without comments, with leading and trailing whitespace removed.
34-
"""
35-
if res := COMMENT_RE.search(line):
36-
line = line[: res.start()]
37-
return line.strip()
3823

3924

4025
@dataclass(eq=False)
@@ -377,7 +362,7 @@ def parse_steps(self, steps_data: list[GherkinStep]) -> list[Step]:
377362
current_type = keyword
378363
steps.append(
379364
Step(
380-
name=strip_comments(step.text),
365+
name=step.text,
381366
type=current_type,
382367
indent=step.location.column - 1,
383368
line_number=step.location.line,
@@ -401,7 +386,7 @@ def parse_scenario(self, scenario_data: GherkinScenario, feature: Feature) -> Sc
401386
templated = bool(scenario_data.examples)
402387
scenario = ScenarioTemplate(
403388
feature=feature,
404-
name=strip_comments(scenario_data.name),
389+
name=scenario_data.name,
405390
line_number=scenario_data.location.line,
406391
templated=templated,
407392
tags=self.get_tag_names(scenario_data.tags),
@@ -451,7 +436,7 @@ def parse(self) -> Feature:
451436
scenarios=OrderedDict(),
452437
filename=self.abs_filename,
453438
rel_filename=self.rel_filename,
454-
name=strip_comments(feature_data.name),
439+
name=feature_data.name,
455440
tags=self.get_tag_names(feature_data.tags),
456441
background=None,
457442
line_number=feature_data.location.line,

tests/args/cfparse/test_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_every_step_takes_param_with_the_same_name(pytester):
1515
When I pay 2 Euro
1616
And I pay 1 Euro
1717
Then I should have 0 Euro
18-
And I should have 999999 Euro # In my dream...
18+
And I should have 999999 Euro
1919
2020
"""
2121
),

tests/args/parse/test_args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_every_steps_takes_param_with_the_same_name(pytester):
1414
When I pay 2 Euro
1515
And I pay 1 Euro
1616
Then I should have 0 Euro
17-
And I should have 999999 Euro # In my dream...
17+
And I should have 999999 Euro
1818
1919
"""
2020
),

tests/feature/test_outline.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def test_unused_params(pytester):
9090
Scenario Outline: Outlined with unused params
9191
Given there are <start> cucumbers
9292
When I eat <eat> cucumbers
93-
# And commented out step with <unused_param>
9493
Then I should have <left> cucumbers
9594
9695
Examples:

tests/feature/test_scenario.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ def test_scenario_comments(pytester):
4545
# Comment
4646
Given I have a bar
4747
48-
Scenario: Strings that are not comments
48+
Scenario: Strings that are not #comments
4949
Given comments should be at the start of words
5050
Then this is not a#comment
51+
And this is not a # comment
5152
And this is not "#acomment"
5253
5354
"""
@@ -65,7 +66,7 @@ def test_scenario_comments(pytester):
6566
def test_1():
6667
pass
6768
68-
@scenario("comments.feature", "Strings that are not comments")
69+
@scenario("comments.feature", "Strings that are not #comments")
6970
def test_2():
7071
pass
7172
@@ -80,9 +81,11 @@ def _():
8081
pass
8182
8283
83-
@then(parsers.parse("this is not {acomment}"))
84-
def _(acomment):
85-
assert re.search("a.*comment", acomment)
84+
@then("this is not a#comment")
85+
@then("this is not a # comment")
86+
@then('this is not "#acomment"')
87+
def _():
88+
pass
8689
8790
"""
8891
)

0 commit comments

Comments
 (0)