|
11 | 11 | sys.path.append( |
12 | 12 | os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
13 | 13 | ) |
14 | | -from api import MOCK_EMBEDDINGS, app, collection, mock_embedding |
15 | 14 |
|
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 |
18 | 18 |
|
19 | 19 |
|
20 | 20 | class TestAPI(unittest.TestCase): |
21 | 21 | """Test cases for the API endpoints.""" |
22 | 22 |
|
| 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 | + |
23 | 51 | def setUp(self): |
24 | 52 | """Set up test environment.""" |
25 | 53 | self.client = TestClient(app) |
|
0 commit comments