Skip to content

test: pin interpreter probe so py-template render test passes on Windows#3428

Merged
mnriem merged 1 commit into
github:mainfrom
mnriem:mnriem-fix-py-interpreter-test-windows
Jul 9, 2026
Merged

test: pin interpreter probe so py-template render test passes on Windows#3428
mnriem merged 1 commit into
github:mainfrom
mnriem:mnriem-fix-py-interpreter-test-windows

Conversation

@mnriem

@mnriem mnriem commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

tests/test_command_template_py_scripts.py::test_template_renders_python_invocation fails on Windows runners (all 6 py:-scripted command templates) while passing on Linux/macOS — see run 29023156913.

Root cause

The _pin_interpreter fixture monkeypatches shutil.which to return /usr/bin/python3, intending to pin the rendered interpreter token to python3. But on Windows, resolve_python_interpreter() guards the which() result with a real _interpreter_runs() subprocess probe (added in #3304 to skip the Microsoft Store App Execution Alias stub):

if sys.platform == "win32" and not IntegrationBase._interpreter_runs(found):
    continue

The mocked /usr/bin/python3 path doesn't exist on a Windows runner, so the probe returns False, both python3 and python are skipped, and the resolver falls back to sys.executable (e.g. C:\hostedtoolcache\...\python.exe). The rendered invocation then starts with a Windows python.exe path instead of python3, failing the assertion:

assert re.search(r"python3 \.specify/scripts/python/\w+\.py(?: --[\w-]+)*", result)

Fix

Patch _interpreter_runs to return True in the _pin_interpreter fixture so the resolved interpreter token stays python3 across all platforms. This keeps the #3304 production guard fully intact — only the test's mock is made platform-independent.

Testing

  • pytest tests/test_command_template_py_scripts.py → 20 passed locally (macOS). The fix targets the Windows-only fallback path.

Opened by GitHub Copilot (model: Claude Opus 4.8) on behalf of @mnriem.

test_template_renders_python_invocation monkeypatches shutil.which to
return /usr/bin/python3, but on Windows resolve_python_interpreter guards
the which() result with a real _interpreter_runs subprocess probe (github#3304).
The mocked /usr/bin/python3 path does not exist on a Windows runner, so the
probe fails, the resolver falls back to sys.executable (a ...python.exe
path), and the python3-anchored regex assertion fails.

Patch _interpreter_runs to return True in the _pin_interpreter fixture so
the resolved interpreter token stays python3 across all platforms, keeping
the github#3304 production guard intact while making the assertion deterministic.

Assisted-by: GitHub Copilot (model: Claude Opus 4.8, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 9, 2026 16:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Windows-only failure in tests/test_command_template_py_scripts.py::test_template_renders_python_invocation by making the interpreter pinning fixture compatible with the Windows runtime-probe behavior in IntegrationBase.resolve_python_interpreter().

Changes:

  • Extend the _pin_interpreter autouse fixture to also monkeypatch IntegrationBase._interpreter_runs() to always return True.
  • Ensure resolve_python_interpreter() consistently resolves to the python3 token under test across platforms (instead of falling back to sys.executable on Windows).
Show a summary per file
File Description
tests/test_command_template_py_scripts.py Pins the Windows-only _interpreter_runs probe during tests so rendered py: invocations stay anchored to python3.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Low

@mnriem mnriem merged commit d075b27 into github:main Jul 9, 2026
12 checks passed
@mnriem mnriem deleted the mnriem-fix-py-interpreter-test-windows branch July 9, 2026 17:21
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.

2 participants