From b9996a9fe6cac94341955718f6385ce62e68806d Mon Sep 17 00:00:00 2001 From: linuskmr Date: Thu, 23 Dec 2021 18:27:49 +0100 Subject: [PATCH] Move fixtures to conftest.py --- backend/src/routes/test_projects.py | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/backend/src/routes/test_projects.py b/backend/src/routes/test_projects.py index 5888e5c..af49ab8 100644 --- a/backend/src/routes/test_projects.py +++ b/backend/src/routes/test_projects.py @@ -11,34 +11,6 @@ from src.main import app from src.models.project import Project -@pytest.fixture(name="session") -def session_fixture(): - """Creates a mock session, that access an in-memory temporary database.""" - - engine = create_engine( - "sqlite://", # In memory database - connect_args={"check_same_thread": False}, # FastAPI's async functions may execute on different threads - poolclass=StaticPool # All threads should access shared memory - ) - SQLModel.metadata.create_all(engine) - with Session(engine) as session: - yield session - - -@pytest.fixture(name="client") -def client_fixture(session: Session): - """Creates a FastAPI TestClient with a mocked session dependency. This causes FastAPI to inject the fake session - into path operation functions, so that we have full control over the mocked database.""" - - def get_session_override(): - return session - - app.dependency_overrides[database.get_session] = get_session_override - client = TestClient(app) - yield client - app.dependency_overrides.clear() - - def test_project_create(client: TestClient): project = {"name": "Uni"} response = client.post("/projects/", json=project)