File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ def setup_database():
31
31
pytest .skip (f"Unable to connect to the database: { e } " )
32
32
33
33
34
+ @pytest .fixture (scope = "session" )
35
+ def app ():
36
+ """Create a FastAPI app."""
37
+ return create_app ()
38
+
39
+
34
40
@pytest .fixture (scope = "function" )
35
41
def db_session (setup_database ):
36
42
"""Create a new database session with a rollback at the end of the test."""
@@ -44,7 +50,7 @@ def db_session(setup_database):
44
50
45
51
46
52
@pytest .fixture (scope = "function" )
47
- def test_db_client (db_session ):
53
+ def test_db_client (app , db_session ):
48
54
"""Create a test client that uses the override_get_db fixture to return a session."""
49
55
50
56
def override_db_session ():
@@ -53,15 +59,13 @@ def override_db_session():
53
59
finally :
54
60
db_session .close ()
55
61
56
- app = create_app ()
57
62
app .router .lifespan = override_db_session
58
63
with TestClient (app ) as test_client :
59
64
yield test_client
60
65
61
66
62
- @pytest .fixture (scope = "function " )
63
- def test_client ():
67
+ @pytest .fixture (scope = "session " )
68
+ def test_client (app ):
64
69
"""Create a test client."""
65
- app = create_app ()
66
70
with TestClient (app ) as test_client :
67
71
yield test_client
You can’t perform that action at this time.
0 commit comments