userver: pytest_userver.plugins.config Namespace Reference
Loading...
Searching...
No Matches
pytest_userver.plugins.config Namespace Reference

Detailed Description

Work with the configuration files of the service in testsuite.

Functions

pathlib.Path service_config_path (pytestconfig, service_binary)
 Returns the path to service.yaml file set by command line --service-config option.
pathlib.Path db_dump_schema_path (service_binary, service_tmpdir)
 Runs the service binary with --dump-db-schema argument, dumps the 0_db_schema.sql file with database schema and returns path to it.
pathlib.Path|None service_config_vars_path (pytestconfig)
 Returns the path to config_vars.yaml file set by command line --service-config-vars option.
pathlib.Path|None service_secdist_path (pytestconfig)
 Returns the path to secure_data.json file set by command line --service-secdist option.
pathlib.Path config_fallback_path (pytestconfig)
 Returns the path to dynamic config fallback file set by command line --config-fallback option.
 service_tmpdir (service_binary, tmp_path_factory)
 Returns the path for temporary files.
pathlib.Path service_config_path_temp (service_tmpdir, service_config, service_config_yaml, service_config_vars)
 Dumps the contents of the service_config_yaml and service_config_vars into a static config for testsuite and returns the path to the config file.
dict service_config_yaml (_service_config_hooked)
 Returns the static config values after config patches were applied (config.patch and legacy USERVER_CONFIG_HOOKS).
dict service_config_vars (_service_config_hooked)
 Returns the static config variables (config_vars.yaml) values after config patches were applied (config.patch and legacy USERVER_CONFIG_HOOKS).
None _substitute_values (config, dict service_config_vars, service_env)
Callable[[Any, dict], Any] substitute_config_vars (service_env)
 A function that takes config_yaml, config_vars and applies all substitutions just like the service would.
dict service_config (service_config_yaml, service_config_vars, substitute_config_vars)
 Returns the static config values after config patches were applied (config.patch and legacy USERVER_CONFIG_HOOKS) and with all the '$', environment and fallback variables substituted.
_UserverConfig _original_service_config (service_config_path, service_config_vars_path)
_UserverConfig _service_config_hooked (daemon_scoped_mark, pytestconfig, request, _original_service_config)
Mapping[str, str] _service_config_substitution_vars (request, mockserver_info)
ServiceConfigPatch userver_config_substitutions (_service_config_substitution_vars)
 Replaces substitution vars in all strings within config_vars using string.Template.substitute.
ServiceConfigPatch userver_config_http_server (service_port, monitor_port, choose_free_port)
 Returns a function that adjusts the static configuration file for testsuite.
list[str] allowed_url_prefixes_extra ()
 By default, userver HTTP client is only allowed to talk to mockserver when running in testsuite.
list[str] allowed_url_prefixes (mockserver_info, mockserver_ssl_info, allowed_url_prefixes_extra)
 Returns final list of allowed urls prefixes when running in testsuite.
ServiceConfigPatch userver_config_http_client (allowed_url_prefixes)
 Returns a function that adjusts the static configuration file for testsuite.
str userver_default_log_level ()
 Default log level to use in userver if no command line option was provided.
str userver_log_level (pytestconfig, userver_default_log_level)
 Returns –service-log-level value if provided, otherwise returns userver_default_log_level() value from fixture.
ServiceConfigPatch userver_config_logging (userver_log_level, _service_logfile_path)
 Returns a function that adjusts the static configuration file for testsuite.
ServiceConfigPatch userver_config_logging_otlp ()
 Returns a function that adjusts the static configuration file for testsuite.
ServiceConfigPatch userver_config_testsuite (pytestconfig, mockserver_info)
 Returns a function that adjusts the static configuration file for testsuite.
ServiceConfigPatch userver_config_secdist (service_secdist_path)
 Returns a function that adjusts the static configuration file for testsuite.
ServiceConfigPatch userver_config_testsuite_middleware (bool userver_testsuite_middleware_enabled)
bool userver_testsuite_middleware_enabled ()
 Whether testsuite middleware is enabled.
ServiceConfigPatch userver_config_deadlock_detector (str userver_deadlock_detector_mode)
 Returns a function that adjusts the static configuration file for testsuite.
str userver_deadlock_detector_mode ()
 Returns Deadlock detector mode for testsuite.

Variables

list USERVER_CONFIG_HOOKS
 Prefer pytest_userver.config.patch to patch static config / config_vars before the service starts.
TypeAlias ServiceConfigPatch = Callable[[dict, dict], None]

Function Documentation

◆ _original_service_config()

_UserverConfig _original_service_config ( service_config_path,
service_config_vars_path )
protected

Definition at line 376 of file config.py.

◆ _service_config_hooked()

_UserverConfig _service_config_hooked ( daemon_scoped_mark,
pytestconfig,
request,
_original_service_config )
protected

Definition at line 398 of file config.py.

◆ _service_config_substitution_vars()

Mapping[str, str] _service_config_substitution_vars ( request,
mockserver_info )
protected

Definition at line 422 of file config.py.

◆ _substitute_values()

None _substitute_values ( config,
dict service_config_vars,
service_env )
protected

Definition at line 279 of file config.py.

◆ userver_config_testsuite_middleware()

ServiceConfigPatch userver_config_testsuite_middleware ( bool userver_testsuite_middleware_enabled)

Definition at line 759 of file config.py.

◆ userver_testsuite_middleware_enabled()

bool userver_testsuite_middleware_enabled ( )

Whether testsuite middleware is enabled.

Definition at line 779 of file config.py.

Variable Documentation

◆ ServiceConfigPatch

TypeAlias pytest_userver.plugins.config.ServiceConfigPatch = Callable[[dict, dict], None]

Definition at line 45 of file config.py.

◆ USERVER_CONFIG_HOOKS

list pytest_userver.plugins.config.USERVER_CONFIG_HOOKS

Prefer pytest_userver.config.patch to patch static config / config_vars before the service starts.

USERVER_CONFIG_HOOKS is a legacy list of fixture (or function) names that are applied the same way. Values are collected across pytest plugins and initial conftest modules.

Example with the recommended decorator:

import pathlib
import pytest
pytest_plugins = ['pytest_userver.plugins.core']
@pytest.fixture(scope='session')
@pytest_userver.config.patch
def static_config_hook(service_source_dir):
def _patch_config(config_yaml, config_vars):
components = config_yaml['components_manager']['components']
assert 'fs-cache-main' in components
components['fs-cache-main']['dir'] = str(
pathlib.Path(service_source_dir).joinpath('public'),
)
return _patch_config

Legacy example with USERVER_CONFIG_HOOKS:

USERVER_CONFIG_HOOKS = ['prepare_service_config']
TESTDIR = pathlib.Path(__file__).parent
@pytest.fixture(scope='session')
def prepare_service_config(get_free_port):
def _do_patch(config_yaml, config_vars):
components = config_yaml['components_manager']['components']
grpc_server = components['grpc-server']
grpc_server['tls'] = {
'key': str(TESTDIR / 'private_key.key'),
'cert': str(TESTDIR / 'cert.crt'),
}
# MacOS does not support unix-socket + TLS.
# It seems that recent versions of gRPC (e.g. 1.54.3) also do not support that.
grpc_server.pop('unix-socket-path', None)
if 'port' not in grpc_server:
grpc_server['port'] = get_free_port()
return _do_patch

Definition at line 43 of file config.py.