mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-17 16:50:53 +00:00
refactor: Update test label mapping to load test discovery dynamically
Some checks are pending
Backend Tests / Plan test groups (push) Waiting to run
Backend Tests / (push) Blocked by required conditions
CI Pipeline / prepare (push) Waiting to run
CI Pipeline / docker (amd64, ubuntu-24.04) (push) Blocked by required conditions
CI Pipeline / docker (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
CI Pipeline / create-manifest (push) Blocked by required conditions
Build and Push Multi-Arch Docker Image / build-and-push (push) Waiting to run
Some checks are pending
Backend Tests / Plan test groups (push) Waiting to run
Backend Tests / (push) Blocked by required conditions
CI Pipeline / prepare (push) Waiting to run
CI Pipeline / docker (amd64, ubuntu-24.04) (push) Blocked by required conditions
CI Pipeline / docker (arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
CI Pipeline / create-manifest (push) Blocked by required conditions
Build and Push Multi-Arch Docker Image / build-and-push (push) Waiting to run
Revised the import mechanism for the test discovery module to load it dynamically by file path, avoiding eager loading of the `dispatcharr` package. This change ensures that the script can run in a bare Python environment before the application virtual environment is set up, improving compatibility with CI processes.
This commit is contained in:
parent
d93cb6265f
commit
080a2bbd74
1 changed files with 26 additions and 3 deletions
|
|
@ -1,17 +1,40 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Map changed repository paths to Django test package labels for CI."""
|
||||
"""Map changed repository paths to Django test package labels for CI.
|
||||
|
||||
Loads ``dispatcharr/test_discovery.py`` by file path so this script does not
|
||||
import the ``dispatcharr`` package (which eagerly loads Celery). The label step
|
||||
runs on the bare runner Python before the app venv exists.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(REPO_ROOT))
|
||||
|
||||
from dispatcharr.test_discovery import labels_for_changed_paths # noqa: E402
|
||||
|
||||
def _load_test_discovery():
|
||||
path = REPO_ROOT / "dispatcharr" / "test_discovery.py"
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"dispatcharr_test_discovery",
|
||||
path,
|
||||
)
|
||||
if spec is None or spec.loader is None:
|
||||
raise ImportError(f"Unable to load test discovery module from {path}")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
# Register before exec so dataclasses/typing edge cases that re-import
|
||||
# the module name still resolve.
|
||||
sys.modules[spec.name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
_test_discovery = _load_test_discovery()
|
||||
labels_for_changed_paths = _test_discovery.labels_for_changed_paths
|
||||
|
||||
|
||||
def _read_paths(argv: list[str]) -> list[str]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue