Coverage for tests/test_tutorial/test_sql_databases/test_testing_databases.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1import importlib 1abcde

2import os 1abcde

3from pathlib import Path 1abcde

4 

5import pytest 1abcde

6 

7from ...utils import needs_pydanticv1 1abcde

8 

9 

10# TODO: pv2 add version with Pydantic v2 

11@needs_pydanticv1 1abcde

12def test_testing_dbs(tmp_path_factory: pytest.TempPathFactory): 1abcde

13 tmp_path = tmp_path_factory.mktemp("data") 1abcde

14 cwd = os.getcwd() 1abcde

15 os.chdir(tmp_path) 1abcde

16 test_db = Path("./test.db") 1abcde

17 if test_db.is_file(): # pragma: nocover 1abcde

18 test_db.unlink() 

19 # Import while creating the client to create the DB after starting the test session 

20 from docs_src.sql_databases.sql_app.tests import test_sql_app 1abcde

21 

22 # Ensure import side effects are re-executed 

23 importlib.reload(test_sql_app) 1abcde

24 test_sql_app.test_create_user() 1abcde

25 if test_db.is_file(): # pragma: nocover 1abcde

26 test_db.unlink() 

27 os.chdir(cwd) 1abcde