7USERVER_CONFIG_HOOKS = [
'_userver_config_dumps']
10@pytest.fixture(scope='session')
11def userver_dumps_root(tmp_path_factory) -> pathlib.Path:
13 The directory which the service will use for cache dumps.
14 Dumps of individual components will be stored in
15 `{userver_dumps_root}/{component-name}/{datetime}-v{format-version}`
17 @see userver::dump::Dumper
18 @ingroup userver_testsuite_fixtures
20 path = tmp_path_factory.mktemp(
'userver-cache-dumps', numbered=
True)
25def read_latest_dump(userver_dumps_root):
27 Read the latest dump produced by a specified dumper.
29 @see userver::dump::Dumper
30 @ingroup userver_testsuite_fixtures
33 def read(dumper_name: str) -> typing.Optional[bytes]:
34 specific_dir = userver_dumps_root.joinpath(dumper_name)
35 if not specific_dir.is_dir():
37 latest_dump_filename = max(
40 for f
in specific_dir.iterdir()
41 if specific_dir.joinpath(f).is_file()
45 if not latest_dump_filename:
47 with open(specific_dir.joinpath(latest_dump_filename),
'rb')
as dump:
54def cleanup_userver_dumps(userver_dumps_root, request):
56 To avoid leaking dumps between tests, cache_dump_dir must be cleaned after
57 each test. To observe the dumps, add a final `time.sleep(1000000)` to your
58 test locally. The returned function may also be used to clean dumps
59 manually as appropriate.
61 @see userver::dump::Dumper
62 @ingroup userver_testsuite_fixtures
65 def cleanup() -> None:
66 shutil.rmtree(userver_dumps_root, ignore_errors=
True)
67 userver_dumps_root.mkdir()
69 request.addfinalizer(cleanup)
73@pytest.fixture(scope='session')
74def _userver_config_dumps(pytestconfig, userver_dumps_root):
75 def patch_config(_config, config_vars) -> None:
76 config_vars[
'userver-dumps-root'] = str(userver_dumps_root)
77 if not pytestconfig.getoption(
'--service-runner-mode',
False):
78 config_vars[
'userver-dumps-periodic'] =
False