Skip to content

Support custom error message in SetupError #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from typing import Generator
from dotenv import load_dotenv
from sqlmodel import create_engine, Session, select
from sqlalchemy import Engine
Expand All @@ -14,7 +15,9 @@
# Define a custom exception for test setup errors
class SetupError(Exception):
"""Exception raised for errors in the test setup process."""
pass
def __init__(self, message="An error occurred during test setup"):
self.message = message
super().__init__(self.message)


@pytest.fixture(scope="session")
Expand All @@ -30,7 +33,7 @@ def engine() -> Engine:


@pytest.fixture(scope="session", autouse=True)
def set_up_database(engine):
def set_up_database(engine) -> Generator[None, None, None]:
"""
Set up the test database before running the test suite.
Drop all tables and recreate them to ensure a clean state.
Expand All @@ -41,7 +44,7 @@ def set_up_database(engine):


@pytest.fixture
def session(engine):
def session(engine) -> Generator[Session, None, None]:
"""
Provide a session for database operations in tests.
"""
Expand All @@ -50,7 +53,7 @@ def session(engine):


@pytest.fixture(autouse=True)
def clean_db(session: Session):
def clean_db(session: Session) -> None:
"""
Cleans up the database tables before each test.
"""
Expand All @@ -63,7 +66,7 @@ def clean_db(session: Session):

# Test user fixture
@pytest.fixture()
def test_user(session: Session):
def test_user(session: Session) -> User:
"""
Creates a test user in the database.
"""
Expand All @@ -80,7 +83,7 @@ def test_user(session: Session):

# Unauthenticated client fixture
@pytest.fixture()
def unauth_client(session: Session):
def unauth_client(session: Session) -> Generator[TestClient, None, None]:
"""
Provides a TestClient instance without authentication.
"""
Expand All @@ -95,7 +98,7 @@ def get_session_override():

# Authenticated client fixture
@pytest.fixture()
def auth_client(session: Session, test_user: User):
def auth_client(session: Session, test_user: User) -> Generator[TestClient, None, None]:
"""
Provides a TestClient instance with valid authentication tokens.
"""
Expand All @@ -117,7 +120,7 @@ def get_session_override():


@pytest.fixture
def test_organization(session: Session):
def test_organization(session: Session) -> Organization:
"""Create a test organization for use in tests"""
organization = Organization(name="Test Organization")
session.add(organization)
Expand Down
Loading