Improve testing
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -7,6 +7,7 @@
|
|||||||
"appendonly",
|
"appendonly",
|
||||||
"appname",
|
"appname",
|
||||||
"asgiref",
|
"asgiref",
|
||||||
|
"autouse",
|
||||||
"Behaviour",
|
"Behaviour",
|
||||||
"cacd",
|
"cacd",
|
||||||
"cellspacing",
|
"cellspacing",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
@ -8,6 +9,8 @@ from django.contrib import messages
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from platformdirs import user_data_dir
|
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.
|
# Parse a .env file and then load all the variables found as environment variables.
|
||||||
load_dotenv(verbose=True)
|
load_dotenv(verbose=True)
|
||||||
|
|
||||||
|
40
core/tests/conftest.py
Normal file
40
core/tests/conftest.py
Normal 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)
|
@ -97,6 +97,12 @@ DJANGO_SETTINGS_MODULE = "core.settings"
|
|||||||
# Only run tests in files that match this pattern.
|
# Only run tests in files that match this pattern.
|
||||||
python_files = ["*_test.py"]
|
python_files = ["*_test.py"]
|
||||||
|
|
||||||
|
# Enable logging in the console.
|
||||||
|
log_cli = true
|
||||||
|
log_cli_level = "INFO"
|
||||||
|
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
|
||||||
|
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
plugins = ["mypy_django_plugin.main"]
|
plugins = ["mypy_django_plugin.main"]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user