userver: pytest_userver.grpc.MockserverSession Class Reference
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
pytest_userver.grpc.MockserverSession Class Reference

Detailed Description

Allows to install mocks that are kept active between tests, see grpc_mockserver_session.

Warning
This is a sharp knife, use with caution! For most use-cases, prefer grpc_mockserver instead.

Definition at line 34 of file __init__.py.

Public Member Functions

None __init__ (self, *, grpc.aio.Server server, bool experimental=False)
 
None reset_mocks (self)
 Removes all mocks for this mockserver that have been installed using MockserverSession or Mockserver API.
 
 asyncexc_append_scope (self, Optional[AsyncExcAppend] asyncexc_append)
 Sets testsuite's asyncexc_append for use in the returned scope.
 
grpc.aio.Server server (self)
 The underlying grpc.aio.Server.
 
None start (self)
 Starts the server.
 
None stop (self)
 Stops the server properly.
 
MockserverSession __aenter__ (self)
 
None __aexit__ (self, exc_type, exc_val, exc_tb)
 

Protected Member Functions

_ServiceMock _get_auto_service_mock (self, type servicer_class)
 
None _set_asyncexc_append (self, Optional[AsyncExcAppend] asyncexc_append)
 

Protected Attributes

grpc.aio.Server _server = server
 
dict _auto_service_mocks = {}
 
Optional[AsyncExcAppend] _asyncexc_append = None
 

Constructor & Destructor Documentation

◆ __init__()

None pytest_userver.grpc.MockserverSession.__init__ ( self,
* ,
grpc.aio.Server server,
bool experimental = False )
Warning
This initializer is an experimental API, likely to break in the future. Consider using grpc_mockserver_session instead.

Initializes MockserverSession. Takes ownership of server. To properly start and stop the server, use MockserverSession as an async contextmanager:

async with pytest_userver.grpc.mockserver.MockserverSession(server=server) as mockserver:
# ...
Note
MockserverSession is usually obtained from grpc_mockserver_session.

Definition at line 43 of file __init__.py.

Member Function Documentation

◆ __aenter__()

MockserverSession pytest_userver.grpc.MockserverSession.__aenter__ ( self)

Definition at line 119 of file __init__.py.

◆ __aexit__()

None pytest_userver.grpc.MockserverSession.__aexit__ ( self,
exc_type,
exc_val,
exc_tb )

Definition at line 123 of file __init__.py.

◆ _get_auto_service_mock()

_ServiceMock pytest_userver.grpc.MockserverSession._get_auto_service_mock ( self,
type servicer_class )
protected

Definition at line 64 of file __init__.py.

◆ _set_asyncexc_append()

None pytest_userver.grpc.MockserverSession._set_asyncexc_append ( self,
Optional[AsyncExcAppend] asyncexc_append )
protected

Definition at line 74 of file __init__.py.

◆ asyncexc_append_scope()

pytest_userver.grpc.MockserverSession.asyncexc_append_scope ( self,
Optional[AsyncExcAppend] asyncexc_append )

Sets testsuite's asyncexc_append for use in the returned scope.

Definition at line 89 of file __init__.py.

◆ reset_mocks()

None pytest_userver.grpc.MockserverSession.reset_mocks ( self)

Removes all mocks for this mockserver that have been installed using MockserverSession or Mockserver API.

Note
Mocks installed manually using MockserverSession.server will not be removed, though.

Definition at line 79 of file __init__.py.

◆ server()

grpc.aio.Server pytest_userver.grpc.MockserverSession.server ( self)

The underlying grpc.aio.Server.

Definition at line 100 of file __init__.py.

◆ start()

None pytest_userver.grpc.MockserverSession.start ( self)

Starts the server.

Note
Prefer starting mockserver using the async contextmanager syntax if possible.

Definition at line 106 of file __init__.py.

◆ stop()

None pytest_userver.grpc.MockserverSession.stop ( self)

Stops the server properly.

Prefer this method to stopping server manually.

Definition at line 113 of file __init__.py.

Member Data Documentation

◆ _asyncexc_append

pytest_userver.grpc.MockserverSession._asyncexc_append = None
protected

Definition at line 62 of file __init__.py.

◆ _auto_service_mocks

dict pytest_userver.grpc.MockserverSession._auto_service_mocks = {}
protected

Definition at line 61 of file __init__.py.

◆ _server

pytest_userver.grpc.MockserverSession._server = server
protected

Definition at line 60 of file __init__.py.


The documentation for this class was generated from the following file: