Allows to install mocks that are reset between tests, see grpc_mockserver.
Acts as a scope for the installed mocks. Mocks are removed on __exit__ or reset_mocks call.
Definition at line 134 of file __init__.py.
Public Member Functions | |
| None | __init__ (self, *, MockserverSession mockserver_session, bool experimental=False) |
| MockDecorator | __call__ (self, servicer_method) |
| Returns a decorator to mock the specified gRPC service method implementation. | |
| Callable[[str], MockDecorator] | mock_factory (self, servicer_class) |
| Allows to create a fixture as a shorthand for mocking methods of the specified gRPC service. | |
| Servicer | install_servicer (self, Servicer servicer) |
Installs as a mock servicer, the class of which should inherit from a generated *Servicer class. | |
| None | reset_mocks (self) |
Removes all mocks installed using this Mockserver instance. | |
| MockserverSession | __enter__ (self) |
| None | __exit__ (self, exc_type, exc_val, exc_tb) |
Protected Member Functions | |
| _ServiceMock | _get_service_mock (self, type servicer_class) |
Protected Attributes | |
| _mockserver_session = mockserver_session | |
| _token = _MockHandlerRemovalToken() | |
| set[_ServiceMock] | _installed_service_mocks = set() |
| None pytest_userver.grpc.Mockserver.__init__ | ( | self, | |
| * | , | ||
| MockserverSession | mockserver_session, | ||
| bool | experimental = False ) |
Initializes Mockserver. Should be used together with context manager syntax (with block).
Mockserver is usually obtained from grpc_mockserver.An example on creating a custom scope for gRPC mocks:
Definition at line 142 of file __init__.py.
| MockDecorator pytest_userver.grpc.Mockserver.__call__ | ( | self, | |
| servicer_method ) |
Returns a decorator to mock the specified gRPC service method implementation.
Example:
Definition at line 160 of file __init__.py.
| MockserverSession pytest_userver.grpc.Mockserver.__enter__ | ( | self | ) |
Definition at line 232 of file __init__.py.
| None pytest_userver.grpc.Mockserver.__exit__ | ( | self, | |
| exc_type, | |||
| exc_val, | |||
| exc_tb ) |
Definition at line 235 of file __init__.py.
|
protected |
Definition at line 238 of file __init__.py.
| Servicer pytest_userver.grpc.Mockserver.install_servicer | ( | self, | |
| Servicer | servicer ) |
Installs as a mock servicer, the class of which should inherit from a generated *Servicer class.
Write a service implementation:
*Servicer classes at once is allowed.Install servicer instance:
Use service mock:
Definition at line 193 of file __init__.py.
| Callable[[str], MockDecorator] pytest_userver.grpc.Mockserver.mock_factory | ( | self, | |
| servicer_class ) |
Allows to create a fixture as a shorthand for mocking methods of the specified gRPC service.
Example:
Definition at line 173 of file __init__.py.
| None pytest_userver.grpc.Mockserver.reset_mocks | ( | self | ) |
Removes all mocks installed using this Mockserver instance.
Definition at line 224 of file __init__.py.
|
protected |
Definition at line 158 of file __init__.py.
|
protected |
Definition at line 156 of file __init__.py.
|
protected |
Definition at line 157 of file __init__.py.