Skip to content

Commit

Permalink
Only patch yaml parser on test load (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelboulton committed Dec 15, 2022
1 parent 3923c9c commit c5b23b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 12 additions & 0 deletions tavern/testutils/pytesthook/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

import attr
import pytest
import yaml

from tavern.core import run_test
from tavern.plugins import load_plugins
from tavern.schemas.files import verify_tests
from tavern.testutils.pytesthook import call_hook
from tavern.util import exceptions
from tavern.util.loader import error_on_empty_scalar
from tavern.util.report import attach_text

from .error import ReprdError
Expand All @@ -29,13 +31,23 @@ class YamlItem(pytest.Item):
spec (dict): The whole dictionary of the test
"""

# See https://github.com/taverntesting/tavern/issues/825
_patched_yaml = False

def __init__(self, *, name, parent, spec, path, **kwargs):
super().__init__(name, parent, **kwargs)
self.path = path
self.spec = spec

self.global_cfg = {}

if not YamlItem._patched_yaml:
yaml.parser.Parser.process_empty_scalar = (
error_on_empty_scalar
) # type:ignore

YamlItem._patched_yaml = True

@classmethod
def yamlitem_from_parent(cls, name, parent, spec, path):
return cls.from_parent(parent, name=name, spec=spec, path=path)
Expand Down
3 changes: 0 additions & 3 deletions tavern/util/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,3 @@ def error_on_empty_scalar(self, mark): # pylint: disable=unused-argument
)

raise exceptions.BadSchemaError(error)


yaml.parser.Parser.process_empty_scalar = error_on_empty_scalar # type:ignore

0 comments on commit c5b23b5

Please sign in to comment.