Skip to content

fix(core): make subprocess and temporary file tests portable on Windows - #39664

Merged
ccurme (ccurme) merged 4 commits into
langchain-ai:masterfrom
Jacopos311:fix-windows-tests
Aug 18, 2026
Merged

fix(core): make subprocess and temporary file tests portable on Windows#39664
ccurme (ccurme) merged 4 commits into
langchain-ai:masterfrom
Jacopos311:fix-windows-tests

Conversation

@Jacopos311

Copy link
Copy Markdown
Contributor

Both changes are complete and verified. Here's a summary of what was done in this PR (closes #39647):

Changes

1. libs/core/tests/unit_tests/test_imports.pytest_importable_all_via_subprocess

  • Added import sys.
  • Replaced the bare "python" string in the subprocess.run([...]) call with sys.executable.

Why: On Windows, a bare python invocation from a subprocess can resolve to the base Windows PATH interpreter rather than the interpreter running the test (the active uv environment). Since the test imports a module that may only be installed in the uv environment, this previously caused the subprocess import to fail on Windows. Using sys.executable guarantees the subprocess uses the same active interpreter.

2. libs/core/tests/unit_tests/prompts/test_prompt.pytest_from_file_encoding

  • Removed the now-unused from tempfile import NamedTemporaryFile import.
  • Added from pathlib import Path.
  • Refactored the test to use pytest's tmp_path fixture: the file is written with file_path.write_text(template, encoding="cp1252") and subsequently read via PromptTemplate.from_file(file_path, ...), which accepts str | Path.

Why: The original test kept a NamedTemporaryFile open (the file handle stays active inside the with block) while attempting to reopen that same path. On Windows this triggers a PermissionError due to file locking. Using tmp_path writes and closes the file before any subsequent reads, avoiding the lock entirely while keeping the temporary-file cleanup behavior.

Verification

  • Ran both affected tests with uv run pytest: 2 passed.
  • Ran ruff check and ruff format --check on both files: all checks passed.

No public API signatures were changed — these are test-only modifications.

@github-actions github-actions Bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix size: XS < 50 LOC labels Aug 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically closed because you are not assigned to the linked issue.

Opening a PR before assignment is discouraged and is not an indication that it will be accepted. This process exists so maintainers can confirm a change is aligned with the project direction before contributors invest time implementing it. Please:

  1. Comment on the linked issue explaining the approach you would like to take and why — include enough detail for a maintainer to evaluate the design. Do not post a drive-by "please assign me" comment with no substance; those will be ignored.
  2. Wait for a maintainer to approve the approach and assign you. Once assigned, this PR can be reopened automatically.

Maintainers: reopen this PR or remove the missing-issue-link label to bypass this check.

# Conflicts:
#	libs/core/tests/unit_tests/prompts/test_prompt.py
@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 15 untouched benchmarks
⏩ 2 skipped benchmarks1


Comparing Jacopos311:fix-windows-tests (9db6d14) with master (b5e8e2e)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@ccurme
ccurme (ccurme) merged commit c8b2d76 into langchain-ai:master Aug 18, 2026
96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-issue-check core `langchain-core` package issues & PRs external fix For PRs that implement a fix new-contributor size: XS < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core tests fail on Windows because subprocess and temporary file handling are not portable

2 participants