-
Notifications
You must be signed in to change notification settings - Fork 128
/
conftest.py
66 lines (55 loc) · 1.85 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
import sys
import pytest
from django.conf import settings
def pytest_addoption(parser):
# https://docs.pytest.org/en/7.1.x/example/markers.html#custom-marker-and-command-line-option-to-control-test-runs
parser.addoption("--test-spatial", action="store_true", default=False)
def should_run_spatial(config):
return config.getoption("--test-spatial")
def pytest_runtest_setup(item):
requires_spatial = any(mark.name == "spatial" for mark in item.iter_markers())
if requires_spatial:
if not should_run_spatial(item.config):
pytest.skip("cannot run without the --test-spatial parameter")
def pytest_configure(config):
COMMON_CONFIG = dict(
STATIC_URL="",
INSTALLED_APPS=[
"location_field",
"tests",
],
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
},
],
)
if sys.platform == "darwin":
COMMON_CONFIG["SPATIALITE_LIBRARY_PATH"] = "/usr/local/lib/mod_spatialite.dylib"
elif sys.version_info[0] == 2:
COMMON_CONFIG["SPATIALITE_LIBRARY_PATH"] = "mod_spatialite"
if should_run_spatial(config):
settings.configure(
**dict(
COMMON_CONFIG,
DATABASES={
"default": {
"ENGINE": "django.contrib.gis.db.backends.spatialite",
"NAME": "db.sqlite3",
}
},
)
)
else:
settings.configure(
**dict(
COMMON_CONFIG,
DATABASES={
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "db.sqlite3",
}
},
)
)