-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconftest.py
58 lines (37 loc) · 1.15 KB
/
conftest.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pytest
POOL_OF_RAMOS = {'backend_type': ['path.to.backend']}
_SETTINGS = None
@pytest.fixture(autouse=True)
def reset_pools():
import ramos
ramos.configure(pools=POOL_OF_RAMOS)
@pytest.fixture(autouse=True)
def reset_settings():
if _SETTINGS:
try:
_SETTINGS.configure(POOL_OF_RAMOS=POOL_OF_RAMOS)
except RuntimeError:
_SETTINGS.POOL_OF_RAMOS = POOL_OF_RAMOS
@pytest.fixture
def settings():
if _SETTINGS is None:
pytest.skip('The django or simple_settings are not installed.')
return _SETTINGS
def pytest_configure():
global _SETTINGS
try:
import django
from django.conf import settings
settings.configure(POOL_OF_RAMOS=POOL_OF_RAMOS)
django.setup()
_SETTINGS = settings
except ImportError:
try:
import os
os.environ.setdefault('SIMPLE_SETTINGS', 'conftest')
from simple_settings import settings
settings.configure(POOL_OF_RAMOS=POOL_OF_RAMOS)
_SETTINGS = settings
except ImportError:
import ramos
ramos.configure(pools=POOL_OF_RAMOS)