test_api_images and test_api_prompts installed a MagicMock folder_paths,
so whenever one of them was imported before test_api_autotag the later
patch("folder_paths.get_output_directory") in test_api_history_outputs
left a mock attribute behind and two test_diagnostics_config tests
failed. tests/host_stubs.py now installs one real-module stub, used by
test_api_images, test_api_prompts and test_api_autotag (and through
test_api_images by the annotation modules, whose copy is gone), so the
modules pass in either import order.
30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
"""One stand-in for ComfyUI's ``folder_paths`` module, shared by every test.
|
|
|
|
Test modules that import the API standalone need a ``folder_paths`` module.
|
|
It must be a real module, not a ``MagicMock``: ``patch("folder_paths.x",
|
|
create=True)`` then adds and removes plain attributes, while a mock would
|
|
hand a later test an auto-created child (or lose the attribute on exit), so
|
|
the outcome depended on which test module discovery imported first.
|
|
"""
|
|
|
|
import sys
|
|
import tempfile
|
|
import types
|
|
|
|
|
|
def install_folder_paths_stub() -> types.ModuleType:
|
|
"""Install the shared ``folder_paths`` stub unless a real module is there.
|
|
|
|
A test that installs its own stand-in for a while (and restores it) is
|
|
left alone; a ``MagicMock`` left behind by older code is replaced.
|
|
"""
|
|
current = sys.modules.get("folder_paths")
|
|
if isinstance(current, types.ModuleType):
|
|
return current
|
|
stub = types.ModuleType("folder_paths")
|
|
stub.models_dir = tempfile.gettempdir()
|
|
stub.base_path = tempfile.gettempdir()
|
|
stub.get_output_directory = tempfile.gettempdir
|
|
sys.modules["folder_paths"] = stub
|
|
return stub
|