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