-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
46 lines (35 loc) · 1.49 KB
/
conftest.py
File metadata and controls
46 lines (35 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright (c) 2026 Guy's and St Thomas' NHS Foundation Trust & King's College London
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
from unittest.mock import MagicMock, patch
import pytest
from fastapi.testclient import TestClient
# Set required environment variables before importing the app
# This must happen before fl_api.config is imported
os.environ.setdefault("FL_ADMIN_DIRECTORY", "/tmp/test_admin")
from fl_api.app import app
from fl_api.core.dependencies import get_session
@pytest.fixture
def mock_session():
return MagicMock()
@pytest.fixture
def client(mock_session):
with patch("fl_api.app.create_fl_session", return_value=mock_session):
with TestClient(app, raise_server_exceptions=False) as test_client:
yield test_client
@pytest.fixture(autouse=True)
def override_session(client):
from unittest.mock import MagicMock
fake_session = MagicMock()
app.dependency_overrides[get_session] = lambda: fake_session
yield
app.dependency_overrides.clear()