Skip to content

Commit 8ec7868

Browse files
authored
tests(cli[sync_sigint]) Survive distro relative-PYTHONPATH builds (#549)
The single subprocess-based test in vcspull's CLI suite failed on distro builders (e.g. Arch Linux PKGBUILD) that test staged-install wheels through a relative ``PYTHONPATH`` entry from the source tree. The root ``conftest.py``'s autouse ``cwd_default`` fixture chdirs each test into a per-test ``tmp_path``, the subprocess inherits that CWD, and the relative ``PYTHONPATH`` then resolves to a non-existent path -- the child fails with ``ModuleNotFoundError: No module named 'vcspull'``. ``uv run pytest`` masks the bug because the venv exposes vcspull via absolute site-packages. - **Anchor** the subprocess to vcspull's actually-loaded install location via ``importlib.util.find_spec``, then prepend that absolute directory to the child's ``PYTHONPATH``. - **Preserve** any incoming ``PYTHONPATH`` so other build setups remain unaffected. - **Audit** the rest of the codebase for the same failure mode -- this is the only test that spawns a Python subprocess importing vcspull, so the fix closes the full exposure surface. - **Document** the packager-visible behaviour change under the CHANGES ``### Development`` section so distros can confirm the test-suite portability fix in release notes.
2 parents 833f234 + ffd1308 commit 8ec7868

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

CHANGES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ $ uvx --from 'vcspull' --prerelease allow vcspull
3737
_Notes on upcoming releases will be added here_
3838
<!-- END PLACEHOLDER - ADD NEW CHANGELOG ENTRIES BELOW THIS LINE -->
3939

40+
### Development
41+
42+
#### Test suite works under distro relative-`PYTHONPATH` builds (#549)
43+
44+
Distributions that test built wheels by staging them into a directory
45+
and pointing pytest at that directory via a relative `PYTHONPATH` entry
46+
from the source tree (the common Arch Linux PKGBUILD pattern) can now
47+
run vcspull's full test suite end to end.
48+
4049
## vcspull v1.60.0 (2026-05-18)
4150

4251
vcspull v1.60.0 is a maintenance release for the May 2026 docs and

tests/cli/test_sync_sigint.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from __future__ import annotations
44

5+
import importlib.util
56
import os
7+
import pathlib
68
import signal
79
import subprocess
810
import sys
@@ -55,7 +57,24 @@ def test_exit_on_sigint_produces_wifsignaled_sigint() -> None:
5557
" _exit_on_sigint()\n"
5658
)
5759

58-
env = {**os.environ, "PYTHONDONTWRITEBYTECODE": "1"}
60+
# Pin the child's import path to wherever the parent loaded vcspull from.
61+
# The root conftest's autouse ``cwd_default`` chdirs every test into a
62+
# per-test ``tmp_path``, which the subprocess inherits as its CWD. Build
63+
# environments that hand vcspull to pytest via a *relative* ``PYTHONPATH``
64+
# entry (e.g. Arch's ``tmp_install/usr/lib/pythonX.Y/site-packages``)
65+
# would then resolve that entry against the tmp dir and fail to import
66+
# vcspull. Prepending the parent's resolved package dir keeps the child
67+
# importable regardless of the surrounding install style.
68+
vcspull_spec = importlib.util.find_spec("vcspull")
69+
assert vcspull_spec is not None and vcspull_spec.origin is not None
70+
vcspull_parent = str(pathlib.Path(vcspull_spec.origin).resolve().parent.parent)
71+
env = {
72+
**os.environ,
73+
"PYTHONDONTWRITEBYTECODE": "1",
74+
"PYTHONPATH": os.pathsep.join(
75+
p for p in (vcspull_parent, os.environ.get("PYTHONPATH", "")) if p
76+
),
77+
}
5978

6079
proc = subprocess.run(
6180
[sys.executable, "-c", runner],

0 commit comments

Comments
 (0)