-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ckan_setup.py
34 lines (24 loc) · 936 Bytes
/
ckan_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
from ckan.cli import load_config
def pytest_addoption(parser):
"""Allow using custom config file during tests.
"""
parser.addoption(u"--ckan-ini", action=u"store")
def pytest_sessionstart(session):
"""Initialize CKAN environment.
"""
load_config(session.config.option.ckan_ini)
def pytest_runtest_setup(item):
"""Automatically apply `ckan_config` fixture if test has `ckan_config`
mark.
`ckan_config` mark itself does nothing(as any mark). All actual
config changes performed inside `ckan_config` fixture. So let's
implicitely use `ckan_config` fixture inside any test that patches
config object. This will save us from adding
`@mark.usefixtures("ckan_config")` every time.
"""
custom_config = [
mark.args for mark in item.iter_markers(name=u"ckan_config")
]
if custom_config:
item.fixturenames.append(u"ckan_config")