-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconftest.py
More file actions
25 lines (20 loc) · 976 Bytes
/
conftest.py
File metadata and controls
25 lines (20 loc) · 976 Bytes
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
"""
Root conftest.py — makes the collection importable as ansible_collections.opsmill.infrahub
when running pytest directly from the repo root (e.g. `uv run pytest tests/unit/`).
The collection root IS this repository. We create a symlink so that
ansible_collections/opsmill/infrahub → repo root, then add that parent directory
to sys.path. This mirrors what ansible-galaxy collection install does.
"""
from __future__ import annotations
import sys
from pathlib import Path
def pytest_configure(config: object) -> None:
repo_root = Path(__file__).parent.resolve()
collections_dir = repo_root / ".pytest_collections"
link_target = collections_dir / "ansible_collections" / "opsmill" / "infrahub"
link_target.parent.mkdir(parents=True, exist_ok=True)
if not link_target.exists():
link_target.symlink_to(repo_root)
collections_str = str(collections_dir)
if collections_str not in sys.path:
sys.path.insert(0, collections_str)