Skip to content

Commit 23fc273

Browse files
authored
chore: try fix web app test flakiness (#3126)
1 parent 431d319 commit 23fc273

File tree

5 files changed

+126
-107
lines changed

5 files changed

+126
-107
lines changed

tests/web/conftest.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
from pathlib import Path
22

33
import pytest
4+
from fastapi import FastAPI
45

56
from sqlmesh.core.context import Context
6-
from web.server.main import api_console, app
7+
from web.server.console import api_console
78
from web.server.settings import Settings, get_loaded_context, get_settings
89

910

1011
@pytest.fixture
11-
def project_tmp_path(tmp_path: Path):
12+
def web_app() -> FastAPI:
13+
from web.server.main import create_app
14+
15+
return create_app()
16+
17+
18+
@pytest.fixture
19+
def project_tmp_path(web_app: FastAPI, tmp_path: Path):
1220
def get_settings_override() -> Settings:
1321
return Settings(project_path=tmp_path)
1422

@@ -19,29 +27,29 @@ def get_settings_override() -> Settings:
1927
"""
2028
)
2129

22-
app.dependency_overrides[get_settings] = get_settings_override
30+
web_app.dependency_overrides[get_settings] = get_settings_override
2331
yield tmp_path
24-
app.dependency_overrides = {}
32+
web_app.dependency_overrides = {}
2533

2634

2735
@pytest.fixture
28-
def project_context(project_tmp_path: Path):
36+
def project_context(web_app: FastAPI, project_tmp_path: Path):
2937
context = Context(paths=project_tmp_path, console=api_console)
3038

3139
def get_loaded_context_override() -> Context:
3240
return context
3341

34-
app.dependency_overrides[get_loaded_context] = get_loaded_context_override
42+
web_app.dependency_overrides[get_loaded_context] = get_loaded_context_override
3543
yield context
36-
app.dependency_overrides = {}
44+
web_app.dependency_overrides = {}
3745

3846

3947
@pytest.fixture
40-
def web_sushi_context(sushi_context: Context):
48+
def web_sushi_context(web_app: FastAPI, sushi_context: Context):
4149
def get_context_override() -> Context:
4250
sushi_context.console = api_console
4351
return sushi_context
4452

45-
app.dependency_overrides[get_loaded_context] = get_context_override
53+
web_app.dependency_overrides[get_loaded_context] = get_context_override
4654
yield sushi_context
47-
app.dependency_overrides = {}
55+
web_app.dependency_overrides = {}

tests/web/test_lineage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from __future__ import annotations
22

33
import pytest
4+
from fastapi import FastAPI
45
from fastapi.testclient import TestClient
56

67
from sqlmesh.core.context import Context
7-
from web.server.main import app
88

99
pytestmark = pytest.mark.web
1010

1111

1212
@pytest.fixture
13-
def client() -> TestClient:
14-
return TestClient(app)
13+
def client(web_app: FastAPI) -> TestClient:
14+
return TestClient(web_app)
1515

1616

1717
def test_get_lineage(client: TestClient, web_sushi_context: Context) -> None:

0 commit comments

Comments
 (0)