Skip to content

Commit 79408d9

Browse files
GeneAIclaude
authored andcommitted
fix: Fix Windows CI test failures
- Mock anthropic package in test_all_wizards.py fixtures - Add file handler cleanup in test_logging_config.py (Windows locking) - Use ignore_errors=True for temp dir cleanup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1c4a4fb commit 79408d9

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

tests/test_all_wizards.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Licensed under Fair Source 0.9
99
"""
1010

11+
from unittest.mock import MagicMock, patch
12+
1113
import pytest
1214

1315
# Import from archived wizards location
@@ -32,15 +34,26 @@
3234
from empathy_llm_toolkit import EmpathyLLM
3335

3436

37+
# Mock anthropic package for tests
38+
@pytest.fixture
39+
def mock_anthropic():
40+
"""Mock anthropic module so tests don't require actual package"""
41+
mock_module = MagicMock()
42+
mock_client = MagicMock()
43+
mock_module.Anthropic.return_value = mock_client
44+
with patch.dict("sys.modules", {"anthropic": mock_module}):
45+
yield mock_module
46+
47+
3548
# Test fixtures
3649
@pytest.fixture
37-
def llm_with_security():
50+
def llm_with_security(mock_anthropic):
3851
"""EmpathyLLM instance with security enabled"""
3952
return EmpathyLLM(provider="anthropic", api_key="test-key", enable_security=True)
4053

4154

4255
@pytest.fixture
43-
def llm_without_security():
56+
def llm_without_security(mock_anthropic):
4457
"""EmpathyLLM instance without security"""
4558
return EmpathyLLM(provider="anthropic", api_key="test-key", enable_security=False)
4659

tests/test_logging_config.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,24 @@
2323
)
2424

2525

26+
def _close_all_file_handlers():
27+
"""Close all file handlers to allow temp dir cleanup on Windows"""
28+
for name in list(logging.Logger.manager.loggerDict.keys()):
29+
logger = logging.getLogger(name)
30+
for handler in logger.handlers[:]:
31+
if isinstance(handler, logging.FileHandler):
32+
handler.close()
33+
logger.removeHandler(handler)
34+
35+
2636
@pytest.fixture
2737
def temp_dir():
2838
"""Create temporary directory for test files"""
2939
tmp = tempfile.mkdtemp()
3040
yield tmp
31-
shutil.rmtree(tmp)
41+
# Close file handlers before cleanup (Windows compatibility)
42+
_close_all_file_handlers()
43+
shutil.rmtree(tmp, ignore_errors=True)
3244

3345

3446
@pytest.fixture(autouse=True)
@@ -37,6 +49,8 @@ def reset_logging_config():
3749
LoggingConfig._configured = False
3850
LoggingConfig._loggers = {}
3951
yield
52+
# Close file handlers before cleanup
53+
_close_all_file_handlers()
4054
LoggingConfig._configured = False
4155
LoggingConfig._loggers = {}
4256

0 commit comments

Comments
 (0)