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():
3131 pytest .skip (f"Unable to connect to the database: { e } " )
3232
3333
34+ @pytest .fixture (scope = "session" )
35+ def app ():
36+ """Create a FastAPI app."""
37+ return create_app ()
38+
39+
3440@pytest .fixture (scope = "function" )
3541def db_session (setup_database ):
3642 """Create a new database session with a rollback at the end of the test."""
@@ -44,7 +50,7 @@ def db_session(setup_database):
4450
4551
4652@pytest .fixture (scope = "function" )
47- def test_db_client (db_session ):
53+ def test_db_client (app , db_session ):
4854 """Create a test client that uses the override_get_db fixture to return a session."""
4955
5056 def override_db_session ():
@@ -53,15 +59,13 @@ def override_db_session():
5359 finally :
5460 db_session .close ()
5561
56- app = create_app ()
5762 app .router .lifespan = override_db_session
5863 with TestClient (app ) as test_client :
5964 yield test_client
6065
6166
62- @pytest .fixture (scope = "function " )
63- def test_client ():
67+ @pytest .fixture (scope = "session " )
68+ def test_client (app ):
6469 """Create a test client."""
65- app = create_app ()
6670 with TestClient (app ) as test_client :
6771 yield test_client
You can’t perform that action at this time.
0 commit comments