forked from adamghill/django-unicorn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
67 lines (53 loc) · 1.76 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
59
60
61
62
63
64
65
66
67
from django.conf import settings
import pytest
def pytest_configure():
templates = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["tests"],
}
]
databases = {"default": {"ENGINE": "django.db.backends.sqlite3",}}
installed_apps = [
"example.coffee",
]
unicorn_settings = {
"SERIAL": {"ENABLED": True, "TIMEOUT": 5},
"CACHE_ALIAS": "default",
"APPS": ("unicorn",),
}
caches = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "unique-snowflake",
}
}
settings.configure(
TEMPLATES=templates,
ROOT_URLCONF="django_unicorn.urls",
DATABASES=databases,
INSTALLED_APPS=installed_apps,
UNIT_TEST=True,
UNICORN=unicorn_settings,
CACHES=caches,
)
@pytest.fixture(autouse=True)
def reset_settings(settings):
"""
This takes the original `UNICORN` settings before the test is run, runs the test, and then resets them afterwards.
This is required because mutating nested dictionaries does not reset them as expected by `pytest-django`.
More details in https://github.com/pytest-dev/pytest-django/issues/601#issuecomment-440676001.
"""
# Get original settings
cache_settings = {**settings.CACHES}
unicorn_settings = {**settings.UNICORN}
django_unicorn_settings = {}
if hasattr(settings, "DJANGO_UNICORN"):
django_unicorn_settings = {**settings.DJANGO_UNICORN}
# Run test
yield
# Re-set original settings
settings.CACHES = cache_settings
settings.UNICORN = unicorn_settings
if django_unicorn_settings:
settings.DJANGO_UNICORN = django_unicorn_settings