Github   Telegram
Loading...
Searching...
No Matches
Namespaces | Functions

Fixtures to use with testsuite. More...

+ Collaboration diagram for Fixtures:

Namespaces

namespace  pytest_userver.plugins
 Python plugins that provide fixtures for functional tests with testsuite; see Functional service tests (testsuite) for an introduction.
 

Functions

pathlib.Path pytest_userver.plugins.base.build_dir (pytestconfig)
 Returns the build directory set by command line --build-dir option. More...
 
pathlib.Path pytest_userver.plugins.base.service_binary (pytestconfig)
 Returns the path to service binary set by command line --service-binary option. More...
 
int pytest_userver.plugins.base.service_port (pytestconfig)
 Returns the main listener port number of the service set by command line --service-port option. More...
 
int pytest_userver.plugins.base.monitor_port (pytestconfig)
 Returns the monitor listener port number of the service set by command line --monitor-port option. More...
 
def pytest_userver.plugins.base.create_port_health_checker ()
 Returns health checker factory function with sinature 'def create_health_checker(*, hostname: str, port: int)' that should return 'async def checker(*, session, process) -> bool' function for health checking of the service. More...
 
pathlib.Path pytest_userver.plugins.config.service_config_path (pytestconfig)
 Returns the path to service.yaml file set by command line --service-config option. More...
 
pathlib.Path pytest_userver.plugins.config.service_config_vars_path (pytestconfig)
 Returns the path to config_vars.yaml file set by command line --service-config-vars option. More...
 
pathlib.Path pytest_userver.plugins.config.config_fallback_path (pytestconfig)
 Returns the path to dynamic config fallback file set by command line --config-fallback option. More...
 
def pytest_userver.plugins.config.config_service_defaults ()
 Fixture that returns default values for config. More...
 
int pytest_userver.plugins.grpc.grpc_service_port (service_config_yaml)
 Returns the gRPC listener port number of the service that is set in the static configuration file. More...
 
str pytest_userver.plugins.grpc.grpc_service_endpoint (grpc_service_port)
 Returns the gRPC endpoint of the service. More...
 
float pytest_userver.plugins.grpc.grpc_service_timeout (pytestconfig)
 Returns the gRPC timeout for the service that is set by the command line option --service-timeout. More...
 
def pytest_userver.plugins.grpc.grpc_channel (grpc_service_endpoint, grpc_service_deps, grpc_service_timeout, _grpc_session_channel)
 Returns the gRPC channel configured by the parameters from the grpc_service_endpoint fixture. More...
 
def pytest_userver.plugins.grpc.grpc_service_deps (service_client)
 gRPC service dependencies hook. More...
 
str pytest_userver.plugins.grpc_mockserver.grpc_mockserver_endpoint (pytestconfig, _grpc_mockserver_and_port)
 Returns the gRPC endpoint to start the mocking server that is set by command line --grpc-mockserver-host and --grpc-mockserver-port options. More...
 
def pytest_userver.plugins.grpc_mockserver.grpc_mockserver (_grpc_mockserver_and_port)
 Returns the gRPC mocking server. More...
 
def pytest_userver.plugins.grpc_mockserver.create_grpc_mock ()
 Creates the gRPC mock server for the provided type. More...
 
def pytest_userver.plugins.samples.service_source_dir (pytestconfig)
 Returns the path to the service source directory that is set by command line --service-source-dir option. More...
 
def pytest_userver.plugins.service.service_env ()
 Override this to pass extra environment variables to the service. More...
 
def pytest_userver.plugins.service_client.client_deps ()
 Service client dependencies hook. More...
 
client.Client pytest_userver.plugins.service_client.service_client (ensure_daemon_started, mockserver, service_daemon, client_deps, client.TestsuiteClientConfig _testsuite_client_config, _service_client_base, _service_client_testsuite)
 Main fixture that provides access to userver based service. More...
 
client.ClientMonitor pytest_userver.plugins.service_client.monitor_client (service_client, service_client_options, mockserver, str monitor_baseurl, client.TestsuiteClientConfig _testsuite_client_config)
 Main fixture that provides access to userver monitor listener. More...
 
str pytest_userver.plugins.service_client.service_baseurl (service_port)
 Returns the main listener URL of the service. More...
 
str pytest_userver.plugins.service_client.monitor_baseurl (monitor_port)
 Returns the main monitor URL of the service. More...
 

Detailed Description

Fixtures to use with testsuite.

Function Documentation

◆ build_dir()

pathlib.Path pytest_userver.plugins.base.build_dir (   pytestconfig)

Returns the build directory set by command line --build-dir option.

Override this fixture to change the way the build directory is detected by the testsuite.

Definition at line 39 of file base.py.

◆ client_deps()

def pytest_userver.plugins.service_client.client_deps ( )

Service client dependencies hook.

Feel free to override, e.g.:

@pytest.fixture
def client_deps(pgsql):
pass

Definition at line 13 of file service_client.py.

◆ config_fallback_path()

pathlib.Path pytest_userver.plugins.config.config_fallback_path (   pytestconfig)

Returns the path to dynamic config fallback file set by command line --config-fallback option.

Override this fixture to change the way path to dynamic config fallback is provided.

Definition at line 101 of file config.py.

◆ config_service_defaults()

def pytest_userver.plugins.config.config_service_defaults ( )

Fixture that returns default values for config.

You may override it in your local conftest.py or fixture:

@pytest.fixture(scope='session')
def config_service_defaults():
with open('defaults.json') as fp:
return json.load(fp)

Definition at line 297 of file config.py.

◆ create_grpc_mock()

def pytest_userver.plugins.grpc_mockserver.create_grpc_mock ( )

Creates the gRPC mock server for the provided type.

@pytest.fixture(scope='session')
def mock_grpc_greeter_session(
greeter_services, grpc_mockserver, create_grpc_mock,
):
mock = create_grpc_mock(greeter_services.GreeterServiceServicer)
greeter_services.add_GreeterServiceServicer_to_server(
mock.servicer, grpc_mockserver,
)
return mock
@pytest.fixture
def mock_grpc_greeter(mock_grpc_greeter_session):
with mock_grpc_greeter_session.mock() as mock:
yield mock

Definition at line 103 of file grpc_mockserver.py.

◆ create_port_health_checker()

def pytest_userver.plugins.base.create_port_health_checker ( )

Returns health checker factory function with sinature 'def create_health_checker(*, hostname: str, port: int)' that should return 'async def checker(*, session, process) -> bool' function for health checking of the service.

Override this fixture to change the way testsuite detects the tested service being alive.

Definition at line 94 of file base.py.

◆ grpc_channel()

def pytest_userver.plugins.grpc.grpc_channel (   grpc_service_endpoint,
  grpc_service_deps,
  grpc_service_timeout,
  _grpc_session_channel 
)

Returns the gRPC channel configured by the parameters from the grpc_service_endpoint fixture.

Definition at line 66 of file grpc.py.

◆ grpc_mockserver()

def pytest_userver.plugins.grpc_mockserver.grpc_mockserver (   _grpc_mockserver_and_port)

Returns the gRPC mocking server.

Override this fixture to change the way the gRPC mocking server is started by the testsuite.

@pytest.fixture(scope='session')
def mock_grpc_greeter_session(
greeter_services, grpc_mockserver, create_grpc_mock,
):
mock = create_grpc_mock(greeter_services.GreeterServiceServicer)
greeter_services.add_GreeterServiceServicer_to_server(
mock.servicer, grpc_mockserver,
)
return mock
@pytest.fixture
def mock_grpc_greeter(mock_grpc_greeter_session):
with mock_grpc_greeter_session.mock() as mock:
yield mock

Definition at line 81 of file grpc_mockserver.py.

◆ grpc_mockserver_endpoint()

str pytest_userver.plugins.grpc_mockserver.grpc_mockserver_endpoint (   pytestconfig,
  _grpc_mockserver_and_port 
)

Returns the gRPC endpoint to start the mocking server that is set by command line --grpc-mockserver-host and --grpc-mockserver-port options.

Override this fixture to change the way the gRPC endpoint is detected by the testsuite.

USERVER_CONFIG_HOOKS = ['_prepare_service_config']
@pytest.fixture(scope='session')
def _prepare_service_config(grpc_mockserver_endpoint):
def patch_config(config, config_vars):
components = config['components_manager']['components']
components['greeter-client']['endpoint'] = grpc_mockserver_endpoint
return patch_config

Definition at line 58 of file grpc_mockserver.py.

◆ grpc_service_deps()

def pytest_userver.plugins.grpc.grpc_service_deps (   service_client)

gRPC service dependencies hook.

Feel free to override it.

Definition at line 92 of file grpc.py.

◆ grpc_service_endpoint()

str pytest_userver.plugins.grpc.grpc_service_endpoint (   grpc_service_port)

Returns the gRPC endpoint of the service.

Override this fixture to change the way the gRPC endpoint is retrieved by the testsuite for tests.

Definition at line 33 of file grpc.py.

◆ grpc_service_port()

int pytest_userver.plugins.grpc.grpc_service_port (   service_config_yaml)

Returns the gRPC listener port number of the service that is set in the static configuration file.

Override this fixture to change the way the gRPC listener port number is retrieved by the testsuite for tests.

Definition at line 16 of file grpc.py.

◆ grpc_service_timeout()

float pytest_userver.plugins.grpc.grpc_service_timeout (   pytestconfig)

Returns the gRPC timeout for the service that is set by the command line option --service-timeout.

Override this fixture to change the way the gRPC timeout is set.

Definition at line 46 of file grpc.py.

◆ monitor_baseurl()

str pytest_userver.plugins.service_client.monitor_baseurl (   monitor_port)

Returns the main monitor URL of the service.

Override this fixture to change the main monitor URL that the testsuite uses for tests.

Definition at line 111 of file service_client.py.

◆ monitor_client()

client.ClientMonitor pytest_userver.plugins.service_client.monitor_client (   service_client,
  service_client_options,
  mockserver,
str  monitor_baseurl,
client.TestsuiteClientConfig  _testsuite_client_config 
)

Main fixture that provides access to userver monitor listener.

async def test_engine_metrics(service_client, monitor_client):
metric = await monitor_client.single_metric(
'engine.task-processors.tasks.finished',
labels={'task_processor': 'main-task-processor'},
)
assert metric.value > 0
assert metric.labels == {'task_processor': 'main-task-processor'}
metrics_dict = await monitor_client.metrics(
prefix='http.', labels={'http_path': '/ping'},
)
assert metrics_dict
assert 'http.handler.cancelled-by-deadline' in metrics_dict

Definition at line 46 of file service_client.py.

◆ monitor_port()

int pytest_userver.plugins.base.monitor_port (   pytestconfig)

Returns the monitor listener port number of the service set by command line --monitor-port option.

Override this fixture to change the way the monitor listener port number is detected by testsuite.

Definition at line 80 of file base.py.

◆ service_baseurl()

str pytest_userver.plugins.service_client.service_baseurl (   service_port)

Returns the main listener URL of the service.

Override this fixture to change the main listener URL that the testsuite uses for tests.

Definition at line 98 of file service_client.py.

◆ service_binary()

pathlib.Path pytest_userver.plugins.base.service_binary (   pytestconfig)

Returns the path to service binary set by command line --service-binary option.

Override this fixture to change the way the path to service binary is detected by the testsuite.

Definition at line 52 of file base.py.

◆ service_client()

client.Client pytest_userver.plugins.service_client.service_client (   ensure_daemon_started,
  mockserver,
  service_daemon,
  client_deps,
client.TestsuiteClientConfig  _testsuite_client_config,
  _service_client_base,
  _service_client_testsuite 
)

Main fixture that provides access to userver based service.

async def test_ping(service_client):
response = await service_client.get('/ping')
assert response.status == 200

Definition at line 23 of file service_client.py.

◆ service_config_path()

pathlib.Path pytest_userver.plugins.config.service_config_path (   pytestconfig)

Returns the path to service.yaml file set by command line --service-config option.

Override this fixture to change the way path to service.yaml is provided.

Definition at line 74 of file config.py.

◆ service_config_vars_path()

pathlib.Path pytest_userver.plugins.config.service_config_vars_path (   pytestconfig)

Returns the path to config_vars.yaml file set by command line --service-config-vars option.

Override this fixture to change the way path to config_vars.yaml is provided.

Definition at line 87 of file config.py.

◆ service_env()

def pytest_userver.plugins.service.service_env ( )

Override this to pass extra environment variables to the service.

@pytest.fixture(scope='session')
def service_env():
return {'SECDIST_CONFIG': json.dumps(SECDIST_CONFIG)}

Definition at line 12 of file service.py.

◆ service_port()

int pytest_userver.plugins.base.service_port (   pytestconfig)

Returns the main listener port number of the service set by command line --service-port option.

Override this fixture to change the way the main listener port number is detected by the testsuite.

Definition at line 66 of file base.py.

◆ service_source_dir()

def pytest_userver.plugins.samples.service_source_dir (   pytestconfig)

Returns the path to the service source directory that is set by command line --service-source-dir option.

Override this fixture to change the way the path to the service source directory is detected by testsuite.

Definition at line 22 of file samples.py.