Skip to content

Commit cd0baab

Browse files
Merge branch 'main' into 70-fix-password-validation-regex
2 parents f4fa9b8 + cc89a50 commit cd0baab

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

tests/conftest.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from typing import Generator
23
from dotenv import load_dotenv
34
from sqlmodel import create_engine, Session, select
45
from sqlalchemy import Engine
@@ -14,7 +15,9 @@
1415
# Define a custom exception for test setup errors
1516
class SetupError(Exception):
1617
"""Exception raised for errors in the test setup process."""
17-
pass
18+
def __init__(self, message="An error occurred during test setup"):
19+
self.message = message
20+
super().__init__(self.message)
1821

1922

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

3134

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

4245

4346
@pytest.fixture
44-
def session(engine):
47+
def session(engine) -> Generator[Session, None, None]:
4548
"""
4649
Provide a session for database operations in tests.
4750
"""
@@ -50,7 +53,7 @@ def session(engine):
5053

5154

5255
@pytest.fixture(autouse=True)
53-
def clean_db(session: Session):
56+
def clean_db(session: Session) -> None:
5457
"""
5558
Cleans up the database tables before each test.
5659
"""
@@ -61,9 +64,8 @@ def clean_db(session: Session):
6164
session.commit()
6265

6366

64-
# Test user fixture
6567
@pytest.fixture()
66-
def test_user(session: Session):
68+
def test_user(session: Session) -> User:
6769
"""
6870
Creates a test user in the database.
6971
"""
@@ -78,9 +80,8 @@ def test_user(session: Session):
7880
return user
7981

8082

81-
# Unauthenticated client fixture
8283
@pytest.fixture()
83-
def unauth_client(session: Session):
84+
def unauth_client(session: Session) -> Generator[TestClient, None, None]:
8485
"""
8586
Provides a TestClient instance without authentication.
8687
"""
@@ -93,9 +94,8 @@ def get_session_override():
9394
app.dependency_overrides.clear()
9495

9596

96-
# Authenticated client fixture
9797
@pytest.fixture()
98-
def auth_client(session: Session, test_user: User):
98+
def auth_client(session: Session, test_user: User) -> Generator[TestClient, None, None]:
9999
"""
100100
Provides a TestClient instance with valid authentication tokens.
101101
"""
@@ -117,7 +117,7 @@ def get_session_override():
117117

118118

119119
@pytest.fixture
120-
def test_organization(session: Session):
120+
def test_organization(session: Session) -> Organization:
121121
"""Create a test organization for use in tests"""
122122
organization = Organization(name="Test Organization")
123123
session.add(organization)

0 commit comments

Comments
 (0)