fix(tests): deflake custom-nodes uninstall test (global shutil.rmtree patch)#9369
Merged
Pfannkuchensack merged 2 commits intoJul 23, 2026
Merged
Conversation
…stall test
test_rejects_invalid_pack_names_before_filesystem_side_effects patched
invokeai.app.api.routers.custom_nodes.shutil.rmtree, which mutates the
global shutil module. If Python's cyclic GC finalizes a TemporaryDirectory
leaked by any earlier test while the patch is active, tempfile's cleanup
lands on the mock and assert_not_called() fails — seen intermittently in CI
(py3.11 macos-default) as:
AssertionError: Expected 'rmtree' to not have been called. Called 1 times.
Calls: [call('/var/folders/.../tmp7n0m81lc',
onerror=<function TemporaryDirectory._rmtree.<locals>.onerror ...>)]
Patch the router module's shutil attribute instead, so only calls made
through custom_nodes.shutil are intercepted and tempdir finalizers keep
using the real shutil.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pfannkuchensack
enabled auto-merge (squash)
July 23, 2026 01:12
Pfannkuchensack
self-requested a review
July 23, 2026 01:13
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
TestUninstallPackNameValidation::test_rejects_invalid_pack_names_before_filesystem_side_effects(added in #9256) fails intermittently in CI:Seen on
py3.11 macos-defaultin this run on PR #9367 (which doesn't touch this code); the same run passed on re-run.Root cause
The test patches
invokeai.app.api.routers.custom_nodes.shutil.rmtree. Sincecustom_nodes.pydoes a plainimport shutil, that target resolves to the globalshutilmodule — the patch affects every caller in the process, not just the router.Several tests in the suite leak
TemporaryDirectoryobjects inside reference cycles (the CI log shows manyResourceWarning: Implicitly cleaning up <TemporaryDirectory ...>). Whenever the cyclic GC happens to run while the patch is active,tempfile's finalizer callsshutil.rmtree— i.e. the mock — andassert_not_called()fails. The recorded call'sonerror=<TemporaryDirectory._rmtree...>argument shows it is tempdir cleanup, not the router. Whether it fires is pure GC-timing luck, hence one platform failing while five pass.Reproducible deterministically:
Fix
Patch the router module's
shutilattribute (patch("...custom_nodes.shutil")) instead of the globalshutil.rmtree, and assert onmock_shutil.rmtree. Only lookups throughcustom_nodes.shutilhit the mock; tempdir finalizers keep the realshutil.Verified both properties:
shutil.rmtree(target_dir)call into the mock, so the test still catches a broken validator.QA Instructions
uv run pytest tests/app/routers/test_custom_nodes.py— 39 passed.Merge Plan
Squash-merge whenever; test-only change.
Checklist
What's Newcopy (if doing a release after this PR)🤖 Generated with Claude Code