Skip to content

Commit

Permalink
chore: try fix web app test flakiness (#3126)
Browse files Browse the repository at this point in the history
  • Loading branch information
eakmanrq authored Sep 13, 2024
1 parent 431d319 commit 23fc273
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 107 deletions.
28 changes: 18 additions & 10 deletions tests/web/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from pathlib import Path

import pytest
from fastapi import FastAPI

from sqlmesh.core.context import Context
from web.server.main import api_console, app
from web.server.console import api_console
from web.server.settings import Settings, get_loaded_context, get_settings


@pytest.fixture
def project_tmp_path(tmp_path: Path):
def web_app() -> FastAPI:
from web.server.main import create_app

return create_app()


@pytest.fixture
def project_tmp_path(web_app: FastAPI, tmp_path: Path):
def get_settings_override() -> Settings:
return Settings(project_path=tmp_path)

Expand All @@ -19,29 +27,29 @@ def get_settings_override() -> Settings:
"""
)

app.dependency_overrides[get_settings] = get_settings_override
web_app.dependency_overrides[get_settings] = get_settings_override
yield tmp_path
app.dependency_overrides = {}
web_app.dependency_overrides = {}


@pytest.fixture
def project_context(project_tmp_path: Path):
def project_context(web_app: FastAPI, project_tmp_path: Path):
context = Context(paths=project_tmp_path, console=api_console)

def get_loaded_context_override() -> Context:
return context

app.dependency_overrides[get_loaded_context] = get_loaded_context_override
web_app.dependency_overrides[get_loaded_context] = get_loaded_context_override
yield context
app.dependency_overrides = {}
web_app.dependency_overrides = {}


@pytest.fixture
def web_sushi_context(sushi_context: Context):
def web_sushi_context(web_app: FastAPI, sushi_context: Context):
def get_context_override() -> Context:
sushi_context.console = api_console
return sushi_context

app.dependency_overrides[get_loaded_context] = get_context_override
web_app.dependency_overrides[get_loaded_context] = get_context_override
yield sushi_context
app.dependency_overrides = {}
web_app.dependency_overrides = {}
6 changes: 3 additions & 3 deletions tests/web/test_lineage.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from __future__ import annotations

import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient

from sqlmesh.core.context import Context
from web.server.main import app

pytestmark = pytest.mark.web


@pytest.fixture
def client() -> TestClient:
return TestClient(app)
def client(web_app: FastAPI) -> TestClient:
return TestClient(web_app)


def test_get_lineage(client: TestClient, web_sushi_context: Context) -> None:
Expand Down
Loading

0 comments on commit 23fc273

Please sign in to comment.