Fix Python test failures for Windows compatibility#488
Merged
Conversation
- Replace NamedTemporaryFile with TemporaryDirectory for Windows compatibility - Windows cannot delete open files, causing PermissionError on os.unlink() - Use TemporaryDirectory context manager which handles cleanup automatically Fixes #484
Reviewer's GuideRefactors daemon configuration tests to use TemporaryDirectory-based config files instead of NamedTemporaryFile, improving Windows compatibility and simplifying cleanup while preserving existing test behavior and assertions. File-Level Changes
Assessment against linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Since these tests are all using temporary filesystem locations now, consider switching to pytest’s built-in
tmp_path/tmp_path_factoryfixtures instead oftempfile.TemporaryDirectoryto simplify setup and avoid manualos.path.joinusage. - The repeated pattern of creating a temp config file (JSON/YAML) and then loading it could be factored into a small helper to reduce duplication and make it easier to adjust temp-file behavior in one place in the future.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Since these tests are all using temporary filesystem locations now, consider switching to pytest’s built-in `tmp_path`/`tmp_path_factory` fixtures instead of `tempfile.TemporaryDirectory` to simplify setup and avoid manual `os.path.join` usage.
- The repeated pattern of creating a temp config file (JSON/YAML) and then loading it could be factored into a small helper to reduce duplication and make it easier to adjust temp-file behavior in one place in the future.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #484
This PR resolves Python test failures on Windows by fixing temp file handling.
Problem
On Windows,
NamedTemporaryFilewithdelete=Falsefollowed byos.unlink()causesPermissionErrorbecause Windows cannot delete files that are still open.Solution
Replace
NamedTemporaryFilewithTemporaryDirectorycontext manager which:Changes Made
test_load_json_config: UseTemporaryDirectoryinstead ofNamedTemporaryFiletest_load_yaml_config: UseTemporaryDirectoryinstead ofNamedTemporaryFiletest_reload_config: UseTemporaryDirectoryinstead ofNamedTemporaryFiletest_config_with_env_overrides: UseTemporaryDirectoryinstead ofNamedTemporaryFileTest Results
All 30 tests pass:
```
============================== 30 passed in 0.24s ==============================
```
Test Plan
pytest tests/test_daemon_config.py -v- all tests passSummary by Sourcery
Update configuration tests to use directory-based temporary files for better cross-platform compatibility.
Bug Fixes:
Tests: