Merge pull request #195 from The-Compiler/at

Don't parse scenario lines containing @ as tag
This commit is contained in:
Oleg Pidsadnyi 2016-09-19 20:44:16 +02:00 committed by GitHub
commit 6cd65b6404
4 changed files with 38 additions and 2 deletions

View File

@ -1,6 +1,11 @@
Changelog
=========
2.17.2
------
- Fix scenairo lines containing an ``@`` being parsed as a tag. (The-Compiler)
2.17.1
------

View File

@ -3,6 +3,6 @@
from pytest_bdd.steps import given, when, then
from pytest_bdd.scenario import scenario, scenarios
__version__ = '2.17.1'
__version__ = '2.17.2'
__all__ = [given.__name__, when.__name__, then.__name__, scenario.__name__, scenarios.__name__]

View File

@ -134,7 +134,7 @@ def get_tags(line):
:return: List of tags.
"""
if not line or '@' not in line.strip():
if not line or not line.strip().startswith('@'):
return set()
return (
set((tag.lstrip('@') for tag in line.strip().split(' @') if len(tag) > 1))

View File

@ -170,6 +170,37 @@ def test_tag_with_spaces(testdir):
)
def test_at_in_scenario(testdir):
testdir.makefile('.feature', test="""
Feature: At sign in a scenario
Scenario: Tags
Given I have a foo@bar
Scenario: Second
Given I have a baz
""")
testdir.makepyfile("""
from pytest_bdd import given, scenarios
@given('I have a foo@bar')
def i_have_at():
return 'foo@bar'
@given('I have a baz')
def i_have_baz():
return 'baz'
scenarios('test.feature')
""")
result = testdir.runpytest_subprocess('--strict')
result.stdout.fnmatch_lines(
[
"*= 2 passed * =*",
],
)
@pytest.mark.parametrize('line, expected', [
('@foo @bar', {'foo', 'bar'}),
('@with spaces @bar', {'with spaces', 'bar'}),