test(annotations): one shared folder_paths stub for the API test modules
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.
This commit is contained in:
@@ -11,10 +11,8 @@ import hashlib
|
||||
import json
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import types
|
||||
import unittest
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
@@ -22,17 +20,6 @@ from unittest.mock import AsyncMock, patch
|
||||
|
||||
from aiohttp.test_utils import make_mocked_request
|
||||
|
||||
# Discovery imports this module before tests/test_api_autotag.py, whose
|
||||
# ``folder_paths`` stub (a real module, so ``patch(..., create=True)`` can add
|
||||
# and remove attributes) the later modules rely on. Install the same stub
|
||||
# before test_api_images would install a MagicMock in its place.
|
||||
if "folder_paths" not in sys.modules:
|
||||
_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
|
||||
|
||||
try:
|
||||
from test_api_images import ImageAPITestCase, make_png
|
||||
from open_handles import assert_closed, open_handles_under
|
||||
|
||||
Reference in New Issue
Block a user