userver: pytest_userver.sql.RegisteredTrx Class Reference
Loading...
Searching...
No Matches
pytest_userver.sql.RegisteredTrx Class Reference

Detailed Description

RegisteredTrx maintains transaction fault injection state to test transaction failure code path.

You may enable specific transaction failure calling enable_trx_failure on that transaction name. After that, the transaction's Commit method will throw an exception.

If you don't need a fault injection anymore (e.g. you want to test a successfull retry), you may call disable_trx_failure afterwards.

Example usage:

async def test_trx_fail(service_client, pgsql, userver_pg_trx):
response = await service_client.delete('/v1/key-value?key=foo')
assert response.status == 200
userver_pg_trx.enable_failure('sample_transaction_insert_key_value')
response = await service_client.post('/v1/key-value?key=foo&value=bar')
assert response.status == 500
response = await service_client.get('/v1/key-value?key=foo')
assert response.status == 404

Definition at line 1 of file sql.py.

Public Member Functions

 __init__ (self)
 
None enable_failure (self, str name)
 
None disable_failure (self, str name)
 
bool is_failure_enabled (self, str name)
 

Protected Attributes

 _registered_trx
 

Constructor & Destructor Documentation

◆ __init__()

pytest_userver.sql.RegisteredTrx.__init__ ( self)

Definition at line 19 of file sql.py.

Member Function Documentation

◆ disable_failure()

None pytest_userver.sql.RegisteredTrx.disable_failure ( self,
str name )

Definition at line 25 of file sql.py.

◆ enable_failure()

None pytest_userver.sql.RegisteredTrx.enable_failure ( self,
str name )

Definition at line 22 of file sql.py.

◆ is_failure_enabled()

bool pytest_userver.sql.RegisteredTrx.is_failure_enabled ( self,
str name )

Definition at line 29 of file sql.py.

Member Data Documentation

◆ _registered_trx

pytest_userver.sql.RegisteredTrx._registered_trx
protected

Definition at line 20 of file sql.py.


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