Improve testing

This commit is contained in:
2024-12-11 23:30:59 +01:00
parent b0966e7664
commit cfe6e27a7a
4 changed files with 50 additions and 0 deletions

View File

@ -1,5 +1,6 @@
from __future__ import annotations
import logging
import os
from pathlib import Path
from typing import Literal
@ -8,6 +9,8 @@ from django.contrib import messages
from dotenv import load_dotenv
from platformdirs import user_data_dir
logger: logging.Logger = logging.getLogger(__name__)
# Parse a .env file and then load all the variables found as environment variables.
load_dotenv(verbose=True)

40
core/tests/conftest.py Normal file
View File

@ -0,0 +1,40 @@
from __future__ import annotations
import logging
from typing import TYPE_CHECKING
import pytest
if TYPE_CHECKING:
from django.conf import LazySettings
logger: logging.Logger = logging.getLogger(__name__)
@pytest.fixture(autouse=True)
def _media_root(
settings: LazySettings,
tmpdir_factory: pytest.TempPathFactory,
) -> None:
"""Forces django to save media files into temp folder."""
settings.MEDIA_ROOT = tmpdir_factory.mktemp("media", numbered=True)
logger.info("Testing: Media root is set to %s", settings.MEDIA_ROOT)
@pytest.fixture(autouse=True)
def _password_hashers(settings: LazySettings) -> None:
"""Forces django to use fast password hashers for tests."""
settings.PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
logger.info("Testing: Password hashers are set to %s", settings.PASSWORD_HASHERS)
@pytest.fixture(autouse=True)
def _debug(settings: LazySettings) -> None:
"""Sets proper DEBUG and TEMPLATE debug mode for coverage."""
settings.DEBUG = False
for template in settings.TEMPLATES:
template["OPTIONS"]["debug"] = True
logger.info("Testing: DEBUG is set to %s", settings.DEBUG)