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