-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
66 lines (46 loc) · 1.96 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
from pathlib import Path
import pytest
from coverage_badge.__main__ import main as gen_cov_badge
from django.core.management import call_command
# from django.conf import settings
from django.utils.translation import activate
from lwmdb.utils import app_data_path
from mitchells.import_fixtures import MITCHELLS_EXCEL_PATH
BADGE_PATH: Path = Path("docs") / "assets" / "coverage.svg"
@pytest.fixture(autouse=True)
def set_default_language() -> None:
"""Ensure `en-gb` localisation is enforced for testing."""
activate("en-gb")
# @pytest.fixture(scope="session")
# def django_db_setup(django_db_setup, django_db_blocker):
# """Call the `loaddata` command per app to provide test fixtures."""
# with django_db_blocker.unblock():
# call_command(
# "loaddata",
# )
@pytest.fixture(autouse=True)
def media_storage(settings, tmpdir) -> None:
"""Generate a temp path for testing media files."""
settings.MEDIA_ROOT = tmpdir.strpath
@pytest.fixture(scope="session")
def mitchells_data_path() -> Path:
"""Return path to `mitchells` app data."""
return app_data_path("mitchells") / MITCHELLS_EXCEL_PATH
def pytest_sessionfinish(session, exitstatus):
"""Generate badges for docs after tests finish."""
if exitstatus == 0:
BADGE_PATH.parent.mkdir(parents=True, exist_ok=True)
gen_cov_badge(["-o", f"{BADGE_PATH}", "-f"])
@pytest.fixture
def old_data_provider_fixture_path() -> Path:
"""Load old example `newspaper.DataProvider` fixture."""
return Path("lwmdb/tests/initial-test-dataprovider.json")
@pytest.fixture
def updated_data_provider_path() -> Path:
"""Load old example `newspaper.DataProvider` fixture."""
return Path("lwmdb/tests/update-test-dataprovider.json")
@pytest.fixture
@pytest.mark.django_db
def old_data_provider(old_data_provider_fixture_path: Path) -> None:
"""Load old example `newspaper.DataProvider` fixture."""
call_command("loaddata", old_data_provider_fixture_path)