userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
sqlite.py
1
import
pytest
2
3
import
pytest_userver.config
4
5
pytest_plugins = [
'pytest_userver.plugins.core'
]
6
7
8
@pytest.fixture(scope='session')
9
@pytest_userver.config.patch
10
def
userver_sqlite_config(tmp_path_factory):
11
"""
12
Returns a function that adjusts the SQLite static configuration file for the testsuite.
13
Sets the `db-path` to be an in memory DB with shared cache.
14
15
@ingroup userver_testsuite_fixtures
16
"""
17
18
def
_patch_config(config_yaml, config_vars):
19
components = config_yaml[
'components_manager'
][
'components'
]
20
for
params
in
components.values():
21
if
params
and
'db-path'
in
params:
22
params[
'db-path'
] = f
'file:{params["db-path"]}?mode=memory&cache=shared'
23
24
return
_patch_config
25
26
27
@pytest.fixture(scope='session')
28
def
_list_dbpath_components(service_config_yaml):
29
components_list = list()
30
components = service_config_yaml[
'components_manager'
][
'components'
]
31
for
component_name, params
in
components.items():
32
if
params
and
'db-path'
in
params:
33
components_list.append(component_name)
34
return
components_list
35
36
37
@pytest.fixture(autouse=True)
38
async def
sqlite_db(_list_dbpath_components, service_client, testpoint):
39
"""
40
Removes all the data from SQLite tables at the end of the test to guarantee tests isolation.
41
42
@ingroup userver_testsuite_fixtures
43
"""
44
yield
45
46
for
component
in
_list_dbpath_components:
47
try
:
48
await service_client.run_task(f
'sqlite/{component}/clean-db'
)
49
except
service_client.TestsuiteTaskNotFound:
50
pass
testsuite
pytest_plugins
pytest_userver
plugins
sqlite.py
Generated on
for userver by
Doxygen
1.17.0