[Test Improver] test: replace gc.collect+sleep teardown with shutil.rmtree(ignore_errors=True)#395
Draft
danielmeppiel wants to merge 1 commit intomainfrom
Conversation
…ors=True) Closes #185 Replace fragile tearDown patterns (gc.collect + time.sleep) used to work around Windows file-lock timing issues with TemporaryDirectory. Switch to tempfile.mkdtemp() + shutil.rmtree(ignore_errors=True) which is cleaner, faster, and avoids unnecessary test latency. Affected files: - tests/unit/test_deps.py - tests/unit/test_env_variables.py - tests/unit/test_helpers.py (removed empty tearDown) - tests/unit/test_vscode_adapter.py (4 test classes) - tests/unit/workflow/test_workflow.py (removed safe_rmdir helper) All 2261 tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
🤖 Test Improver — automated AI assistant for test improvements
Closes #185
Goal and Rationale
Several test classes used
gc.collect()+time.sleep(0.1)intearDownas a workaround for Windows file-lock timing issues withtempfile.TemporaryDirectory. This pattern was flagged during PR #181 review as fragile and adds unnecessary test latency (~100–500ms per test class).This PR replaces that pattern with
tempfile.mkdtemp()+shutil.rmtree(ignore_errors=True), which is:ignore_errors=Truesilently handles locked files on Windows without retrying or sleepingApproach
For each affected class:
setUp: Replacetempfile.TemporaryDirectory()withtempfile.mkdtemp()(returns path string directly, no.nameneeded)tearDown: Replacegc.collect() + sleep + .cleanup()withshutil.rmtree(path, ignore_errors=True)Affected files:
tests/unit/test_deps.pyTestLoadApmConfigtests/unit/test_env_variables.pyTestEnvironmentVariablesHandlingtests/unit/test_helpers.pytearDown(no temp dir was used)tests/unit/test_vscode_adapter.pytests/unit/workflow/test_workflow.pysafe_rmdirhelper; simplified 2 tearDownsTest Status
✅ All 2261 tests pass
python3 -m uv run pytest tests/unit/ --no-header -q # 2261 passed in 11.13s