Skip to content

Commit 6cd65b6

Browse files
Merge pull request #195 from The-Compiler/at
Don't parse scenario lines containing @ as tag
2 parents e0761dd + 14cc037 commit 6cd65b6

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
2.17.2
5+
------
6+
7+
- Fix scenairo lines containing an ``@`` being parsed as a tag. (The-Compiler)
8+
49
2.17.1
510
------
611

pytest_bdd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
from pytest_bdd.steps import given, when, then
44
from pytest_bdd.scenario import scenario, scenarios
55

6-
__version__ = '2.17.1'
6+
__version__ = '2.17.2'
77

88
__all__ = [given.__name__, when.__name__, then.__name__, scenario.__name__, scenarios.__name__]

pytest_bdd/feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def get_tags(line):
134134
135135
:return: List of tags.
136136
"""
137-
if not line or '@' not in line.strip():
137+
if not line or not line.strip().startswith('@'):
138138
return set()
139139
return (
140140
set((tag.lstrip('@') for tag in line.strip().split(' @') if len(tag) > 1))

tests/feature/test_tags.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,37 @@ def i_have_bar():
170170
)
171171

172172

173+
def test_at_in_scenario(testdir):
174+
testdir.makefile('.feature', test="""
175+
Feature: At sign in a scenario
176+
177+
Scenario: Tags
178+
Given I have a foo@bar
179+
180+
Scenario: Second
181+
Given I have a baz
182+
""")
183+
testdir.makepyfile("""
184+
from pytest_bdd import given, scenarios
185+
186+
@given('I have a foo@bar')
187+
def i_have_at():
188+
return 'foo@bar'
189+
190+
@given('I have a baz')
191+
def i_have_baz():
192+
return 'baz'
193+
194+
scenarios('test.feature')
195+
""")
196+
result = testdir.runpytest_subprocess('--strict')
197+
result.stdout.fnmatch_lines(
198+
[
199+
"*= 2 passed * =*",
200+
],
201+
)
202+
203+
173204
@pytest.mark.parametrize('line, expected', [
174205
('@foo @bar', {'foo', 'bar'}),
175206
('@with spaces @bar', {'with spaces', 'bar'}),

0 commit comments

Comments
 (0)