diff --git a/CHANGES.rst b/CHANGES.rst index 95b5ccf8..c7504c11 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,11 @@ Changelog ========= +2.17.2 +------ + +- Fix scenairo lines containing an ``@`` being parsed as a tag. (The-Compiler) + 2.17.1 ------ diff --git a/pytest_bdd/__init__.py b/pytest_bdd/__init__.py index b00fcebc..786505c1 100644 --- a/pytest_bdd/__init__.py +++ b/pytest_bdd/__init__.py @@ -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__] diff --git a/pytest_bdd/feature.py b/pytest_bdd/feature.py index 23a08caf..61d22388 100644 --- a/pytest_bdd/feature.py +++ b/pytest_bdd/feature.py @@ -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)) diff --git a/tests/feature/test_tags.py b/tests/feature/test_tags.py index 72947c1f..c2b3d5de 100644 --- a/tests/feature/test_tags.py +++ b/tests/feature/test_tags.py @@ -170,6 +170,37 @@ def i_have_bar(): ) +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'}),