-
-
Notifications
You must be signed in to change notification settings - Fork 430
/
Copy pathconftest.py
68 lines (50 loc) · 1.7 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
68
import sys
from os import environ
from pathlib import Path
from typing import Iterable
import pytest
from xdist.scheduler import LoadScopeScheduling
from django_redis.cache import BaseCache
from tests.settings_wrapper import SettingsWrapper
class FixtureScheduling(LoadScopeScheduling):
"""Split by [] value. This is very hackish and might blow up any time!"""
def _split_scope(self, nodeid):
if "[sqlite" in nodeid:
return nodeid.rsplit("[")[-1].replace("]", "")
return None
def pytest_xdist_make_scheduler(log, config):
return FixtureScheduling(config, log)
def pytest_configure(config):
sys.path.insert(0, str(Path(__file__).absolute().parent))
@pytest.fixture()
def settings():
"""A Django settings object which restores changes after the testrun"""
wrapper = SettingsWrapper()
yield wrapper
wrapper.finalize()
@pytest.fixture()
def cache(cache_settings: str) -> Iterable[BaseCache]:
from django import setup
environ["DJANGO_SETTINGS_MODULE"] = f"settings.{cache_settings}"
setup()
from django.core.cache import cache as default_cache
yield default_cache
default_cache.clear()
def pytest_generate_tests(metafunc):
if "cache" in metafunc.fixturenames or "session" in metafunc.fixturenames:
# Mark
settings = [
"sqlite",
"sqlite_gzip",
"sqlite_herd",
"sqlite_json",
"sqlite_lz4",
"sqlite_msgpack",
"sqlite_sentinel",
"sqlite_sentinel_opts",
"sqlite_sharding",
"sqlite_usock",
"sqlite_zlib",
"sqlite_zstd",
]
metafunc.parametrize("cache_settings", settings)