Files
AEmotionStudio-ComfyUI-Disc…/tests/conftest.py
T
AEmotionStudio 87112b8b2a Fix CI tests: Improve test isolation and mock handling
- Add numpy to requirements-nodes.txt
- Create conftest.py for test configuration
- Fix test_numpy_subprocess.py to import real numpy before any mocking
- Fix test_media.py to import real numpy early
- Fix test_image_node_sanitization.py to use MockTensor instead of torch.zeros
2026-01-21 00:46:02 -08:00

53 lines
1.2 KiB
Python

"""
Pytest configuration file for tests.
This module handles test isolation by ensuring that real packages are imported
before any mocking occurs, and by providing cleanup fixtures.
"""
import sys
import os
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# Store references to real modules before any mocking
# This ensures tests that need real numpy/PIL can use them
_real_numpy = None
_real_PIL = None
def pytest_configure(config):
"""Called after command line options have been parsed and all plugins loaded."""
global _real_numpy, _real_PIL
# Import real modules and store references
try:
import numpy
_real_numpy = numpy
except ImportError:
pass
try:
import PIL
import PIL.Image
import PIL.PngImagePlugin
_real_PIL = PIL
except ImportError:
pass
def get_real_numpy():
"""Get the real numpy module, not a mock."""
if _real_numpy is None:
import numpy
return numpy
return _real_numpy
def get_real_PIL():
"""Get the real PIL module, not a mock."""
if _real_PIL is None:
import PIL
return PIL
return _real_PIL