better parsing of comments, fix #99
This commit is contained in:
parent
6edab17dba
commit
41acbf4148
|
@ -1,6 +1,12 @@
|
|||
Changelog
|
||||
=========
|
||||
|
||||
2.6.2
|
||||
-----
|
||||
|
||||
- Parse comments only in the begining of words
|
||||
|
||||
|
||||
2.6.1
|
||||
-----
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""pytest-bdd public API."""
|
||||
|
||||
__version__ = '2.6.1'
|
||||
__version__ = '2.6.2'
|
||||
|
||||
try:
|
||||
from pytest_bdd.steps import given, when, then
|
||||
|
|
|
@ -64,9 +64,8 @@ STEP_PREFIXES = [
|
|||
("And ", None), # Unknown step type,
|
||||
]
|
||||
|
||||
COMMENT_SYMBOLS = "#"
|
||||
|
||||
STEP_PARAM_RE = re.compile("\<(.+?)\>")
|
||||
COMMENT_RE = re.compile('(^|(?<=\s))#')
|
||||
|
||||
|
||||
def get_step_type(line):
|
||||
|
@ -88,10 +87,9 @@ def strip_comments(line):
|
|||
|
||||
:return: Stripped line.
|
||||
"""
|
||||
try:
|
||||
line = line[:line.index(COMMENT_SYMBOLS)]
|
||||
except ValueError:
|
||||
pass
|
||||
res = COMMENT_RE.search(line)
|
||||
if res:
|
||||
line = line[:res.start()]
|
||||
return line.strip()
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
Scenario: Comments
|
||||
# Comment
|
||||
Given I have a bar
|
||||
|
||||
Scenario: Strings that are not comments
|
||||
Given comments should be at the start of words
|
||||
Then this is not a#comment
|
||||
And this is not "#acomment"
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
"""Test scenario decorator."""
|
||||
import pytest
|
||||
import re
|
||||
|
||||
from pytest_bdd import scenario
|
||||
from pytest_bdd import exceptions
|
||||
from pytest_bdd import (
|
||||
scenario,
|
||||
given,
|
||||
then,
|
||||
parsers,
|
||||
exceptions,
|
||||
)
|
||||
|
||||
|
||||
def test_scenario_not_found(request):
|
||||
|
@ -17,6 +23,16 @@ def test_scenario_not_found(request):
|
|||
feature_path=request.fspath.join('..', 'not_found.feature')))
|
||||
|
||||
|
||||
@given('comments should be at the start of words')
|
||||
def comments():
|
||||
pass
|
||||
|
||||
|
||||
@then(parsers.parse('this is not {acomment}'))
|
||||
def a_comment(acomment):
|
||||
assert re.search('a.*comment', acomment)
|
||||
|
||||
|
||||
def test_scenario_comments(request):
|
||||
"""Test comments inside scenario."""
|
||||
|
||||
|
@ -27,4 +43,12 @@ def test_scenario_comments(request):
|
|||
def test():
|
||||
pass
|
||||
|
||||
@scenario(
|
||||
'comments.feature',
|
||||
'Strings that are not comments'
|
||||
)
|
||||
def test2():
|
||||
pass
|
||||
|
||||
test(request)
|
||||
test2(request)
|
||||
|
|
Loading…
Reference in New Issue