openapi-core/tests/integration/conftest.py

31 lines
674 B
Python
Raw Normal View History

2017-09-21 11:51:37 +00:00
from os import path
2020-01-13 15:37:12 +00:00
from openapi_spec_validator.schemas import read_yaml_file
2017-09-21 11:51:37 +00:00
import pytest
from six.moves.urllib import request
from yaml import safe_load
def spec_from_file(spec_file):
directory = path.abspath(path.dirname(__file__))
path_full = path.join(directory, spec_file)
2020-01-13 15:37:12 +00:00
return read_yaml_file(path_full)
2017-09-21 11:51:37 +00:00
def spec_from_url(spec_url):
content = request.urlopen(spec_url)
return safe_load(content)
class Factory(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
@pytest.fixture(scope='session')
def factory():
return Factory(
spec_from_file=spec_from_file,
spec_from_url=spec_from_url,
)