File tree Expand file tree Collapse file tree 3 files changed +31
-15
lines changed
tests/test_tutorial/test_sql_databases Expand file tree Collapse file tree 3 files changed +31
-15
lines changed Original file line number Diff line number Diff line change
1
+ import importlib
1
2
from pathlib import Path
2
3
3
4
import pytest
283
284
284
285
@pytest .fixture (scope = "module" )
285
286
def client ():
287
+ test_db = Path ("./sql_app.db" )
288
+ if test_db .is_file (): # pragma: nocover
289
+ test_db .unlink ()
286
290
# Import while creating the client to create the DB after starting the test session
287
- from sql_databases .sql_app . main import app
291
+ from sql_databases .sql_app import main
288
292
289
- test_db = Path ("./sql_app.db" )
290
- with TestClient (app ) as c :
293
+ # Ensure import side effects are re-executed
294
+ importlib .reload (main )
295
+ with TestClient (main .app ) as c :
291
296
yield c
292
- test_db .unlink ()
297
+ if test_db .is_file (): # pragma: nocover
298
+ test_db .unlink ()
293
299
294
300
295
301
def test_openapi_schema (client ):
Original file line number Diff line number Diff line change
1
+ import importlib
1
2
from pathlib import Path
2
3
3
4
import pytest
283
284
284
285
@pytest .fixture (scope = "module" )
285
286
def client ():
287
+ test_db = Path ("./sql_app.db" )
288
+ if test_db .is_file (): # pragma: nocover
289
+ test_db .unlink ()
286
290
# Import while creating the client to create the DB after starting the test session
287
- from sql_databases .sql_app . alt_main import app
291
+ from sql_databases .sql_app import alt_main
288
292
289
- test_db = Path ("./sql_app.db" )
290
- with TestClient (app ) as c :
293
+ # Ensure import side effects are re-executed
294
+ importlib .reload (alt_main )
295
+
296
+ with TestClient (alt_main .app ) as c :
291
297
yield c
292
- test_db .unlink ()
298
+ if test_db .is_file (): # pragma: nocover
299
+ test_db .unlink ()
293
300
294
301
295
302
def test_openapi_schema (client ):
Original file line number Diff line number Diff line change
1
+ import importlib
1
2
from pathlib import Path
2
3
3
4
4
5
def test_testing_dbs ():
6
+ test_db = Path ("./test.db" )
7
+ if test_db .is_file (): # pragma: nocover
8
+ test_db .unlink ()
5
9
# Import while creating the client to create the DB after starting the test session
6
- from sql_databases .sql_app .tests . test_sql_app import test_create_user
10
+ from sql_databases .sql_app .tests import test_sql_app
7
11
8
- test_db = Path ("./test.db" )
9
- app_db = Path ("./sql_app.db" )
10
- test_create_user ()
11
- test_db .unlink ()
12
- if app_db .is_file (): # pragma: nocover
13
- app_db .unlink ()
12
+ # Ensure import side effects are re-executed
13
+ importlib .reload (test_sql_app )
14
+ test_sql_app .test_create_user ()
15
+ if test_db .is_file (): # pragma: nocover
16
+ test_db .unlink ()
You can’t perform that action at this time.
0 commit comments