-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
50 lines (35 loc) · 1.42 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
"""Configuration file for pytest."""
from django.conf import settings
import pytest
def pytest_configure():
"""Set up Django settings for tests.
`pytest` automatically calls this function once when tests are run.
"""
settings.DEBUG = False
settings.TESTING = True
# The default password hasher is rather slow by design.
# https://docs.djangoproject.com/en/dev/topics/testing/overview/
settings.PASSWORD_HASHERS = (
"django.contrib.auth.hashers.MD5PasswordHasher",
)
settings.EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
# To disable celery in tests
settings.CELERY_TASK_ALWAYS_EAGER = True
@pytest.fixture(scope="session", autouse=True)
def django_db_setup(django_db_setup):
"""Set up test db for testing."""
@pytest.fixture(autouse=True)
# pylint: disable=invalid-name
def enable_db_access_for_all_tests(django_db_setup, db):
"""Enable access to DB for all tests."""
@pytest.fixture(scope="session", autouse=True)
def temp_directory_for_media(tmpdir_factory):
"""Fixture that set temp directory for all media files.
This fixture changes FILE_STORAGE to filesystem and provides temp dir for
media. PyTest cleans up this temp dir by itself after few test runs
"""
settings.DEFAULT_FILE_STORAGE = (
"django.core.files.storage.FileSystemStorage"
)
media = tmpdir_factory.mktemp("tmp_media")
settings.MEDIA_ROOT = media