1
1
import pytest
2
+ from typing import Generator
2
3
from dotenv import load_dotenv
3
4
from sqlmodel import create_engine , Session , select
4
5
from sqlalchemy import Engine
14
15
# Define a custom exception for test setup errors
15
16
class SetupError (Exception ):
16
17
"""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 )
18
21
19
22
20
23
@pytest .fixture (scope = "session" )
@@ -30,7 +33,7 @@ def engine() -> Engine:
30
33
31
34
32
35
@pytest .fixture (scope = "session" , autouse = True )
33
- def set_up_database (engine ):
36
+ def set_up_database (engine ) -> Generator [ None , None , None ] :
34
37
"""
35
38
Set up the test database before running the test suite.
36
39
Drop all tables and recreate them to ensure a clean state.
@@ -41,7 +44,7 @@ def set_up_database(engine):
41
44
42
45
43
46
@pytest .fixture
44
- def session (engine ):
47
+ def session (engine ) -> Generator [ Session , None , None ] :
45
48
"""
46
49
Provide a session for database operations in tests.
47
50
"""
@@ -50,7 +53,7 @@ def session(engine):
50
53
51
54
52
55
@pytest .fixture (autouse = True )
53
- def clean_db (session : Session ):
56
+ def clean_db (session : Session ) -> None :
54
57
"""
55
58
Cleans up the database tables before each test.
56
59
"""
@@ -63,7 +66,7 @@ def clean_db(session: Session):
63
66
64
67
# Test user fixture
65
68
@pytest .fixture ()
66
- def test_user (session : Session ):
69
+ def test_user (session : Session ) -> User :
67
70
"""
68
71
Creates a test user in the database.
69
72
"""
@@ -80,7 +83,7 @@ def test_user(session: Session):
80
83
81
84
# Unauthenticated client fixture
82
85
@pytest .fixture ()
83
- def unauth_client (session : Session ):
86
+ def unauth_client (session : Session ) -> Generator [ TestClient , None , None ] :
84
87
"""
85
88
Provides a TestClient instance without authentication.
86
89
"""
@@ -95,7 +98,7 @@ def get_session_override():
95
98
96
99
# Authenticated client fixture
97
100
@pytest .fixture ()
98
- def auth_client (session : Session , test_user : User ):
101
+ def auth_client (session : Session , test_user : User ) -> Generator [ TestClient , None , None ] :
99
102
"""
100
103
Provides a TestClient instance with valid authentication tokens.
101
104
"""
@@ -117,7 +120,7 @@ def get_session_override():
117
120
118
121
119
122
@pytest .fixture
120
- def test_organization (session : Session ):
123
+ def test_organization (session : Session ) -> Organization :
121
124
"""Create a test organization for use in tests"""
122
125
organization = Organization (name = "Test Organization" )
123
126
session .add (organization )
0 commit comments