Skip to content

tests(cli[sync_sigint]) Anchor subprocess to vcspull's resolved location#549

Merged
tony merged 2 commits into
masterfrom
fix-test-sync-sigint-relative-pythonpath
May 16, 2026
Merged

tests(cli[sync_sigint]) Anchor subprocess to vcspull's resolved location#549
tony merged 2 commits into
masterfrom
fix-test-sync-sigint-relative-pythonpath

Conversation

@tony
Copy link
Copy Markdown
Member

@tony tony commented May 16, 2026

Summary

  • Fix a test failure for distros (e.g. Arch Linux) that run vcspull's test suite against a staged-install directory referenced via a relative PYTHONPATH entry.
  • Anchor the subprocess spawned by test_exit_on_sigint_produces_wifsignaled_sigint to vcspull's actual install location via importlib.util.find_spec, then prepend that absolute directory to the child's PYTHONPATH.
  • Preserve the original PYTHONPATH so other build environments remain unaffected.

Root cause

Distros stage built wheels into a tree like tmp_install/usr/lib/pythonX.Y/site-packages/ and run pytest from the source dir with a relative PYTHONPATH=tmp_install/usr/lib/pythonX.Y/site-packages:. The project's root conftest.py has an autouse cwd_default fixture that monkeypatch.chdir(tmp_path)s every test. When test_exit_on_sigint_produces_wifsignaled_sigint calls subprocess.run([sys.executable, "-c", runner], env={**os.environ, ...}), the child inherits the per-test tmp_path as its CWD and the relative PYTHONPATH. The child resolves the relative entry against the tmp dir, finds nothing, and from vcspull.cli.sync import _exit_on_sigint fails with ModuleNotFoundError: No module named 'vcspull'. uv run pytest masks the bug because the venv exposes vcspull via absolute site-packages.

Reproduced locally by staging the built wheel into ./tmp_install/... and running PYTHONNOUSERSITE=1 PYTHONPATH="\$STAGE:" python3.14 -s -m pytest tests/cli/test_sync_sigint.py — yields the same stderr as the original failure.

Test plan

  • `uv run pytest tests/cli/test_sync_sigint.py -v` — the target test passes in the dev env
  • `PYTHONNOUSERSITE=1 PYTHONPATH="$STAGE:" python3.14 -s -m pytest tests/cli/test_sync_sigint.py` — same test passes under a relative-`PYTHONPATH` staged-install setup (previously failed with `ModuleNotFoundError`)
  • `uv run pytest` — full suite passes
  • `uv run ruff format .` — clean
  • `uv run ruff check .` — clean
  • `uv run mypy` — clean

…solved location

why: Distro packagers (e.g. Arch Linux) test built wheels by staging
them into a directory like ``tmp_install/usr/lib/python3.14/site-packages``
and pointing pytest at it via a *relative* ``PYTHONPATH`` entry from
the source tree. The root conftest's autouse ``cwd_default`` fixture
chdirs every test into a per-test ``tmp_path``, which the subprocess
launched by ``test_exit_on_sigint_produces_wifsignaled_sigint``
inherits as its CWD. The child then resolves the relative
``PYTHONPATH`` against the tmp dir, where the staged wheel does not
exist, and the test fails with ``ModuleNotFoundError: No module named
'vcspull'``. ``uv run pytest`` masks the bug because the venv exposes
``vcspull`` via absolute site-packages.

what:
- Locate ``vcspull``'s parent directory via
  ``importlib.util.find_spec`` and prepend it (absolute) to the child
  interpreter's ``PYTHONPATH``.
- Preserve any incoming ``PYTHONPATH`` entry so other build setups
  remain unaffected.
- Use ``find_spec`` rather than a bare ``import vcspull`` to keep
  ``mypy --strict`` quiet about the missing ``py.typed`` marker.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.61%. Comparing base (833f234) to head (ffd1308).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #549   +/-   ##
=======================================
  Coverage   83.61%   83.61%           
=======================================
  Files          29       29           
  Lines        4114     4114           
  Branches      813      813           
=======================================
  Hits         3440     3440           
  Misses        440      440           
  Partials      234      234           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

why: Capture the packager-visible behaviour change so distros can see
in the release notes that vcspull's test suite once again runs end to
end under staged-install plus relative ``PYTHONPATH``.
@tony tony force-pushed the fix-test-sync-sigint-relative-pythonpath branch from 9cacd1b to ffd1308 Compare May 16, 2026 12:21
@tony tony merged commit 8ec7868 into master May 16, 2026
8 checks passed
@tony tony deleted the fix-test-sync-sigint-relative-pythonpath branch May 16, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant