Functions, fixtures and classes to do functional testing with testsuite.
Nested Groups | |
| Fixtures | |
| Fixtures to use with testsuite. | |
Namespaces | |
| namespace | pytest_userver |
| Python module pytest_userver provides testsuite support for userver services. | |
| namespace | pytest_userver.chaos |
| Python module that provides testsuite support for chaos tests; see Chaos Testing for an introduction. | |
| namespace | pytest_userver.client |
| Python module that provides clients for functional tests with testsuite; see Functional service tests (testsuite) for an introduction. | |
| namespace | pytest_userver.dynconf |
| Python module that provides classes and constants that may be useful when working with the dynamic config in testsuite. | |
| namespace | pytest_userver.fixture_markers |
| Utilities for attaching typed marks to pytest fixture functions and querying those marks during a test session. | |
| namespace | pytest_userver.metrics |
| Python module that provides helpers for functional testing of metrics with testsuite; see Functional service tests (testsuite) for an introduction. | |
Classes | |
| class | pytest_userver.chaos.GateRoute |
| Class that describes the route for TcpGate or UdpGate. More... | |
| class | pytest_userver.chaos.BaseGate |
| This base class maintain endpoints of two types: More... | |
| class | pytest_userver.chaos.TcpGate |
| Implements TCP chaos-proxy logic such as accepting incoming tcp client connections. More... | |
| class | pytest_userver.chaos.UdpGate |
| Implements UDP chaos-proxy logic such as demuxing incoming datagrams from different clients. More... | |
| class | pytest_userver.client.ClientWrapper |
| Base asyncio userver client that implements HTTP requests to service. More... | |
| class | pytest_userver.client.ClientMonitor |
| Asyncio userver client for monitor listeners, typically retrieved from plugins.service_client.monitor_client fixture. More... | |
| class | pytest_userver.client.MetricsDiffer |
| A helper class for computing metric differences. More... | |
| class | pytest_userver.client.Client |
| Asyncio userver client, typically retrieved from plugins.service_client.service_client fixture. More... | |
| class | pytest_userver.grpc._client.PreCallClientInterceptor |
| A simple generic interceptor that allows to insert some code before each RPC is initiated. More... | |
| class | pytest_userver.metrics.Metric |
| Metric type that contains the labels: dict[str, str] and value: int. More... | |
| class | pytest_userver.metrics.MetricsSnapshot |
| Snapshot of captured metrics that mimics the dict interface. More... | |
| class | pytest_userver.plugins.generated_tests.GeneratedTestsPluginHooks |
| Custom pytest (pluggy) hooks customizing generated tests. More... | |
| class | pytest_userver.sql.RegisteredTrx |
| RegisteredTrx maintains transaction fault injection state to test transaction failure code path. More... | |
| class | pytest_userver.utils.net.HostPort |
| Class that holds a host and port. More... | |
| class | pytest_userver.utils.net.HealthChecks |
| Class that holds all the info for health checks. More... | |
Functions | |
| Callable[..., object] | pytest_userver.config.patch (Callable[..., object] func) |
| Mark a pytest fixture as a static config patch. | |
| Sequence[grpc.aio.ClientInterceptor] | pytest_userver.plugins.grpc._hookspec.pytest_grpc_client_interceptors (pytest.FixtureRequest request) |
| A pytest hook that returns gRPC client interceptors to use when making requests to the service. | |
| None | pytest_userver.plugins.service_runner.test_service_default (service_client, service_baseurl, monitor_baseurl, request) |
| This is default service runner testcase. | |
| Callable[..., object] | pytest_userver.service.dependency (Callable[..., object] func) |
| Mark a pytest fixture as a service dependency. | |
| bool | pytest_userver.utils.net.check_availability (HealthChecks checks) |
| Checks availability for each provided entry. | |
| HealthChecks | pytest_userver.utils.net.get_health_checks_info (dict service_config) |
| Returns a health checks info that for server.listener, grpc-server.port and server.listener-monitor. | |
| Any | pytest_userver.utils.sync.wait_until (Callable func, *, float relax_period_seconds=ITERATION_PERIOD_SECONDS, float total_wait_seconds=TOTAL_WAIT_SECONDS) |
| Waits for some external event for total_wait_seconds and calls func every relax_period_seconds. | |
| None | pytest_userver.utils.sync.wait (Callable check, *, Any|tuple catch=(), float relax_period_seconds=ITERATION_PERIOD_SECONDS, float total_wait_seconds=TOTAL_WAIT_SECONDS, str failure_msg='Timeout happened while waiting for an event', str|None relax_msg=None) |
| Waits for some external event for total_wait_seconds and calls check every relax_period_seconds. | |
| bool check_availability | ( | HealthChecks | checks | ) |
| Callable[..., object] dependency | ( | Callable[..., object] | func | ) |
Mark a pytest fixture as a service dependency.
This fixture will automatically be depended on by service_daemon_instance fixture.
Apply to the original function, under @pytest.fixture.
Overrides inherit this mark automatically; repeating the decorator is not required, even if the override does not request the original fixture. The dependency resolves to the overriding fixture, not the original one.
Definition at line 19 of file service.py.
| HealthChecks get_health_checks_info | ( | dict | service_config | ) |
| Callable[..., object] patch | ( | Callable[..., object] | func | ) |
Mark a pytest fixture as a static config patch.
The fixture will automatically be applied to the service config.
Apply to the original function, under @pytest.fixture.
Overrides inherit this mark automatically; repeating the decorator is not required, even if the override does not request the original fixture. The override keeps the original marked fixture's position in patch order.
| Sequence[grpc.aio.ClientInterceptor] pytest_grpc_client_interceptors | ( | pytest.FixtureRequest | request | ) |
A pytest hook that returns gRPC client interceptors to use when making requests to the service.
Interceptors are accomulated over all implementations of this hook from all plugins.
Definition at line 10 of file _hookspec.py.
| None test_service_default | ( | service_client, | |
| service_baseurl, | |||
| monitor_baseurl, | |||
| request ) |
This is default service runner testcase.
Feel free to override it in your own tests, e.g.:
Definition at line 34 of file service_runner.py.
| None wait | ( | Callable | check, |
| * | , | ||
| Any | tuple | catch = (), | ||
| float | relax_period_seconds = ITERATION_PERIOD_SECONDS, | ||
| float | total_wait_seconds = TOTAL_WAIT_SECONDS, | ||
| str | failure_msg = 'Timeout happened while waiting for an event', | ||
| str | None | relax_msg = None ) |
Waits for some external event for total_wait_seconds and calls check every relax_period_seconds.
If check returns False or raises NotReady exception (or any exception type referenced in catch), the waiting continues. If check returns True, wait_until() stops and returns. After total_wait_seconds of unsuccessful checks wait_until() raises TimeoutError.
Example:
.. code-block:: python
async def is_ready():
return await conn.is_ready()
await wait_until(try_to_connect_db)
| TimeoutError | after total_wait_seconds of unsuccessful checks |
| Any wait_until | ( | Callable | func, |
| * | , | ||
| float | relax_period_seconds = ITERATION_PERIOD_SECONDS, | ||
| float | total_wait_seconds = TOTAL_WAIT_SECONDS ) |
Waits for some external event for total_wait_seconds and calls func every relax_period_seconds.
If func raises NotReady exception, the waiting continues. If func successfully returns, wait_until() returns the same value. After total_wait_seconds of unsuccessful checks wait_until() raises TimeoutError.
Example:
.. code-block:: python
async def try_to_connect_db():
if not db_conn_is_ok():
raise NotReady()
await wait_until(try_to_connect_db)
| TimeoutError | after total_wait_seconds of unsuccessful checks |