3pytest_plugins = [
'pytest_userver.plugins.core']
5USERVER_CONFIG_HOOKS = [
'userver_sqlite_config']
8@pytest.fixture(scope='session')
9def userver_sqlite_config(tmp_path_factory):
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.
14 @ingroup userver_testsuite_fixtures
17 def _patch_config(config_yaml, config_vars):
18 components = config_yaml[
'components_manager'][
'components']
19 for _, params
in components.items():
20 if params
and 'db-path' in params:
21 params[
'db-path'] = f
'file:{params["db-path"]}?mode=memory&cache=shared'
26@pytest.fixture(scope='session')
27def _list_dbpath_components(service_config_yaml):
28 components_list = list()
29 components = service_config_yaml[
'components_manager'][
'components']
30 for commponent_name, params
in components.items():
31 if params
and 'db-path' in params:
32 components_list.append(commponent_name)
33 return components_list
36@pytest.fixture(autouse=True)
37async def sqlite_db(_list_dbpath_components, service_client, testpoint):
39 Removes all the data from SQLite tables at the end of the test to guarantee tests isolation.
41 @ingroup userver_testsuite_fixtures
45 for component
in _list_dbpath_components:
47 await service_client.run_task(f
'sqlite/{component}/clean-db')
48 except service_client.TestsuiteTaskNotFound: