test: fix os.chdir leak and ConfigManager disk writes in install tests#395
test: fix os.chdir leak and ConfigManager disk writes in install tests#395
Conversation
📝 WalkthroughWalkthroughAdds a pytest autouse fixture to restore the process CWD after each test and expands mocking to include Changes
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #395 +/- ##
=======================================
Coverage 74.71% 74.71%
=======================================
Files 33 33
Lines 3924 3924
=======================================
Hits 2932 2932
Misses 992 992 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/comfy_cli/conftest.py`:
- Line 1: Add a module-level docstring at the top of the
tests/comfy_cli/conftest.py module to satisfy the C0114 lint rule; open the
conftest.py file (where the current top symbol is the module import line "import
os") and insert a concise triple-quoted string describing the purpose of this
test configuration module (e.g., "Test fixtures and configuration for comfy_cli
tests") as the first statement in the file.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3813ec41-4fab-4805-9fae-fe5a5530e79d
📒 Files selected for processing (3)
tests/comfy_cli/conftest.pytests/comfy_cli/test_global_python_install.pytests/comfy_cli/test_install_python_resolution.py
20f7423 to
44fae09
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/comfy_cli/test_install_python_resolution.py (1)
48-133: 🧹 Nitpick | 🔵 TrivialConsider extracting common patch setup to reduce repetition.
All three test methods in
TestExecuteshare nearly identical context manager blocks with 6-7 patches. A helper method or fixture could reduce duplication:♻️ Optional refactor using a helper
def _execute_with_mocks(self, tmp_path, **execute_kwargs): """Run install.execute with standard mocks, return key mock objects.""" repo_dir = str(tmp_path) with ( patch("comfy_cli.command.install.ensure_workspace_python", return_value="/resolved/python") as mock_ensure, patch("comfy_cli.command.install.clone_comfyui"), patch("comfy_cli.command.install.check_comfy_repo", return_value=(True, None)), patch("comfy_cli.command.install.pip_install_comfyui_dependencies") as mock_pip_deps, patch("comfy_cli.command.install.DependencyCompiler") as MockCompiler, patch("comfy_cli.command.install.WorkspaceManager"), patch("comfy_cli.config_manager.ConfigManager"), patch.object(install.workspace_manager, "skip_prompting", True), patch.object(install.workspace_manager, "setup_workspace_manager"), ): MockCompiler.Install_Build_Deps = MagicMock() MockCompiler.return_value = MagicMock() install.execute(comfy_path=repo_dir, **execute_kwargs) return mock_ensure, mock_pip_deps, MockCompiler🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/comfy_cli/test_install_python_resolution.py` around lines 48 - 133, Extract the repeated patch setup in TestExecute into a small helper (e.g., _execute_with_mocks) that centralizes the common patches for ensure_workspace_python, clone_comfyui, check_comfy_repo, pip_install_comfyui_dependencies (or DependencyCompiler depending on test), WorkspaceManager, and ConfigManager and the two patch.object calls on install.workspace_manager; have the helper accept tmp_path and kwargs for install.execute and return the key mock objects (mock_ensure, mock_pip_deps, MockCompiler, etc.) so each test (test_calls_ensure_and_passes_resolved_python, test_fast_deps_passes_python_to_dependency_compiler, test_fast_deps_forwards_skip_torch) calls the helper to run install.execute and then asserts on the returned mocks instead of repeating the with(...) block.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@tests/comfy_cli/test_install_python_resolution.py`:
- Around line 48-133: Extract the repeated patch setup in TestExecute into a
small helper (e.g., _execute_with_mocks) that centralizes the common patches for
ensure_workspace_python, clone_comfyui, check_comfy_repo,
pip_install_comfyui_dependencies (or DependencyCompiler depending on test),
WorkspaceManager, and ConfigManager and the two patch.object calls on
install.workspace_manager; have the helper accept tmp_path and kwargs for
install.execute and return the key mock objects (mock_ensure, mock_pip_deps,
MockCompiler, etc.) so each test (test_calls_ensure_and_passes_resolved_python,
test_fast_deps_passes_python_to_dependency_compiler,
test_fast_deps_forwards_skip_torch) calls the helper to run install.execute and
then asserts on the returned mocks instead of repeating the with(...) block.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1d04af2d-a117-4df4-9042-43bcc17cbada
📒 Files selected for processing (4)
tests/comfy_cli/conftest.pytests/comfy_cli/test_file_utils.pytests/comfy_cli/test_global_python_install.pytests/comfy_cli/test_install_python_resolution.py
💤 Files with no reviewable changes (1)
- tests/comfy_cli/test_file_utils.py
Summary
Follow-up to #394. Fixes two test hygiene issues found during review in tests that call
install.execute():CWD leak:
execute()andpip_install_comfyui_dependencies()callos.chdir(repo_dir)as a side effect, leaking the changed working directory into subsequent tests. Added an autouse_preserve_cwdfixture intests/comfy_cli/conftest.pythat saves and restoresos.getcwd()around every test.ConfigManager disk writes: Tests calling
execute(skip_manager=True)hit the realConfigManager().set()which writes to~/.config/comfy-cli/config.ini. Addedpatch("comfy_cli.config_manager.ConfigManager")to the 4 affected callsites intest_install_python_resolution.pyandtest_global_python_install.py.