Skip to content

Commit ca1c396

Browse files
committed
test: fix test for usage in GH Action CI
1 parent 758c15e commit ca1c396

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

tests/unit/test_api.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,43 @@
1111
sys.path.append(
1212
os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
1313
)
14-
from api import MOCK_EMBEDDINGS, app, collection, mock_embedding
1514

16-
# Set mock mode for testing
17-
os.environ["MOCK_EMBEDDINGS"] = "true"
15+
# Import after path setup
16+
import api
17+
from api import app, collection, mock_embedding
1818

1919

2020
class TestAPI(unittest.TestCase):
2121
"""Test cases for the API endpoints."""
2222

23+
mock_patches = []
24+
25+
@classmethod
26+
def setUpClass(cls):
27+
"""Set up test class with patches."""
28+
# Apply mock patches at class level
29+
cls.mock_embeddings_patch = patch.object(api, "MOCK_EMBEDDINGS", True)
30+
cls.mock_embeddings_patch.start()
31+
cls.mock_patches.append(cls.mock_embeddings_patch)
32+
33+
# Directly patch the verify_dependencies function to do nothing
34+
# This ensures tests aren't affected by dependency checks
35+
async def mock_verify_dependencies():
36+
pass
37+
38+
cls.verify_dependencies_patch = patch.object(
39+
api, "verify_dependencies", mock_verify_dependencies
40+
)
41+
cls.verify_dependencies_patch.start()
42+
cls.mock_patches.append(cls.verify_dependencies_patch)
43+
44+
@classmethod
45+
def tearDownClass(cls):
46+
"""Clean up patches."""
47+
# Stop all patches
48+
for mock_patch in cls.mock_patches:
49+
mock_patch.stop()
50+
2351
def setUp(self):
2452
"""Set up test environment."""
2553
self.client = TestClient(app)

0 commit comments

Comments
 (0)