Skip to content

Commit

Permalink
Issue #308 (#311)
Browse files Browse the repository at this point in the history
* Ignore escaped curly braces

* Ignore comments

* Don't match lines where the yml value starts with `!raw`

* Don't read any comment, including EOL comments
  • Loading branch information
mvanderlee authored and michaelboulton committed Mar 16, 2019
1 parent 54d3334 commit 69f1eab
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tavern/testutils/pytesthook/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ def _print_format_variables(self, tw, code_lines):

def read_formatted_vars(lines):
"""Go over all lines and try to find format variables
This might be a bit wonky if escaped curly braces are used...
"""
for line in lines:
for match in re.finditer(r"(?P<format_var>{.*?})", line):
yield match.group("format_var")
for match in re.finditer(
r"(.*?:\s+!raw)?(?(1).*|.*?(?P<format_var>(?<!{){[^{]*?}))", line
):
if match.group("format_var") is not None:
yield match.group("format_var")

format_variables = list(read_formatted_vars(code_lines))

Expand Down Expand Up @@ -179,7 +180,7 @@ def read_relevant_lines(filename):
with io.open(filename, "r", encoding="utf8") as testfile:
for idx, line in enumerate(testfile.readlines()):
if first_line < idx < last_line:
yield line.rstrip()
yield line.split("#", 1)[0].rstrip()

code_lines = list(read_relevant_lines(self.item.spec.start_mark.name))

Expand Down

0 comments on commit 69f1eab

Please sign in to comment.