Commit b748448a authored by Steffen Vogel's avatar Steffen Vogel 🎅🏼
Browse files

test: added for custom Yaml test case collector / executor

parent e215b563
import os
import subprocess
import pytest
def pytest_collect_file(parent, path):
if path.ext == ".yml" and path.basename.startswith("test_"):
return YamlFile(path, parent)
class YamlFile(pytest.File):
def collect(self):
import yaml # we need a yaml parser, e.g. PyYAML
raw = yaml.safe_load(
for name, spec in sorted(raw.items()):
yield YamlItem(name, self, spec)
class YamlItem(pytest.Item):
def __init__(self, name, parent, spec):
super(YamlItem, self).__init__(name, parent)
if 'args' in spec:
self.args = spec['args']
self.args = [ ]
if 'shell' in spec: = spec['shell']
else: = False
if 'check' in spec: = spec['check']
else: = True
if 'timeout' in spec:
self.timeout = spec['timeout']
self.timeout = 60
if 'cwd' in spec:
self.cwd = spec['cwd']
self.cwd = os.path.realpath(os.path.dirname(__file__) + '/..')
if 'skip' in spec and spec['skip']:
if 'xfail' in spec and spec['xfail']:
if 'cmd' in spec:
self.cmd = spec['cmd']
raise AttributeError('Test is missing mandatory "cmd" attribute')
def runtest(self):
cp =[self.cmd] + self.args,
cwd = self.cwd,
shell =,
timeout = self.timeout,
check = True
def repr_failure(self, excinfo):
return self._repr_failure_py(excinfo, style="short")
def reportinfo(self):
return self.fspath, 0, "yaml: %s" %
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment