Skip to content

Commit 27240b4

Browse files
committed
docs: enhance conftest.py comments to explain why it's required
Add detailed docstring explaining that conftest.py is needed for tox nocov mode where usedevelop=false and the package isn't installed. This clarifies the purpose for future maintainers who might wonder if this file can be removed.
1 parent 9d87ab9 commit 27240b4

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

tests/conftest.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
"""Root pytest configuration."""
1+
"""Root pytest configuration.
2+
3+
This file is required for tests to work in tox nocov mode (usedevelop=false).
4+
5+
In tox.ini, the usedevelop setting varies:
6+
- cover mode: usedevelop=true (package installed in editable mode)
7+
- nocov mode: usedevelop=false (package NOT installed)
8+
9+
When usedevelop=false, Python can't find the vendor module for imports like:
10+
from vendor.dbt_artifacts_parser.parsers.catalog.catalog_v1 import Metadata
11+
12+
This conftest.py adds src/ to sys.path so imports work in both modes.
13+
"""
214
import sys
315
from pathlib import Path
416

517
# Add src directory to Python path for all tests
6-
# This needs to run at import time, before pytest collects tests
18+
# This runs at import time, before pytest collects test modules
719
src_path = Path(__file__).parent.parent / "src"
820
if str(src_path) not in sys.path:
921
sys.path.insert(0, str(src_path))
@@ -12,7 +24,9 @@
1224
def pytest_configure(config):
1325
"""
1426
Hook that runs before test collection.
15-
Ensures src directory is in path before pytest imports test modules.
27+
28+
Ensures src directory is in sys.path before pytest imports test modules.
29+
This is a safety check in case the module-level code above didn't run.
1630
"""
1731
# Double-check src is in path
1832
if str(src_path) not in sys.path:

0 commit comments

Comments
 (0)