mirror of
https://github.com/fastapi/fastapi.git
synced 2026-02-23 18:26:42 -05:00
📝 Add an example of setting up a test database (#1144)
* Add an example of setting up a test database. * 📝 Add/update docs for testing a DB with dependency overrides * 🔧 Update test script, remove line removing test file as it is removed during testing * ✅ Update testing coverage pragma Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
@@ -286,7 +286,7 @@ def client():
|
||||
# Import while creating the client to create the DB after starting the test session
|
||||
from sql_databases.sql_app.main import app
|
||||
|
||||
test_db = Path("./test.db")
|
||||
test_db = Path("./sql_app.db")
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
test_db.unlink()
|
||||
|
||||
@@ -286,7 +286,7 @@ def client():
|
||||
# Import while creating the client to create the DB after starting the test session
|
||||
from sql_databases.sql_app.alt_main import app
|
||||
|
||||
test_db = Path("./test.db")
|
||||
test_db = Path("./sql_app.db")
|
||||
with TestClient(app) as c:
|
||||
yield c
|
||||
test_db.unlink()
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_testing_dbs():
|
||||
# Import while creating the client to create the DB after starting the test session
|
||||
from sql_databases.sql_app.tests.test_sql_app import test_create_user
|
||||
|
||||
test_db = Path("./test.db")
|
||||
app_db = Path("./sql_app.db")
|
||||
test_create_user()
|
||||
test_db.unlink()
|
||||
if app_db.is_file(): # pragma: nocover
|
||||
app_db.unlink()
|
||||
Reference in New Issue
Block a user