Chore: Move unittest directory setup onto the shared fixture (#14172)

The unittest side of the suite built its temp directory tree with
tempfile.mkdtemp and a manually enabled override_settings, cleaned up only if
tearDown ran. That is now gone. DirectoriesMixin lives alongside the layout it
bridges and does nothing but hand the paperless_dirs fixture to TestCase
subclasses as self.dirs, so both halves of the suite get the same twelve
settings, the same directory shapes and cleanup owned by tmp_path.

The mixin moves to paperless_testing.dirs rather than staying in the documents
test utilities, because modules in paperless and paperless_mail import it
across the app boundary. The thirty-eight consuming modules change only their
import line; self.dirs.scratch_dir and its siblings keep working.
This commit is contained in:
Trenton H
2026-09-21 10:57:12 -07:00
committed by GitHub
parent 4c264651e8
commit f440e8d33c
41 changed files with 87 additions and 144 deletions
+15
View File
@@ -14,6 +14,7 @@ from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING
from typing import TypedDict
import pytest
from django.test import override_settings
if TYPE_CHECKING:
@@ -129,3 +130,17 @@ def paperless_environment() -> Iterator[PaperlessDirs]:
yield dirs
finally:
reset_backend()
class DirectoriesMixin:
"""Bridges the directory fixture to unittest TestCase subclasses and to
plain pytest test classes that want `self.dirs`.
Delete once no class depends on it.
"""
dirs: PaperlessDirs
@pytest.fixture(autouse=True)
def _paperless_dirs(self, paperless_dirs: PaperlessDirs) -> None:
self.dirs = paperless_dirs