33This module contains step definitions for both synchronous and asynchronous
44atomic transaction scenarios.
55"""
6-
6+ import asyncio
77import logging
88import os
99import tempfile
1616from features .test_entity import RelatedTestEntity , TestAdminEntity , TestEntity , TestManagerEntity
1717from features .test_entity_factory import TestEntityFactory
1818from features .test_helpers import (
19- SafeAsyncContextManager ,
2019 async_schema_setup ,
2120 get_adapter ,
2221 get_async_adapter ,
2322 get_current_scenario_context ,
24- safe_run_async ,
2523)
2624from sqlalchemy import select
2725
@@ -127,8 +125,7 @@ def step_given_database_initialized(context):
127125
128126 # Create schema with async adapter
129127 logger .info ("Creating database schema with async adapter" )
130- with SafeAsyncContextManager (context ) as ctx :
131- ctx .run (async_schema_setup (async_adapter ))
128+ asyncio .run (async_schema_setup (async_adapter ))
132129
133130 logger .info ("Async adapter and schema setup completed" )
134131 except Exception as e :
@@ -965,7 +962,6 @@ def verify_consistency():
965962
966963
967964@when ("a new entity is created in an async atomic transaction" )
968- @safe_run_async
969965async def step_when_entity_created_in_async_atomic (context ):
970966 """Create a new entity within an async atomic transaction."""
971967 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -993,7 +989,6 @@ async def create_entity_async_atomic():
993989
994990
995991@then ("the async entity should be retrievable" )
996- @safe_run_async
997992async def step_then_async_entity_should_be_retrievable (context ):
998993 """Verify the entity exists after async atomic transaction."""
999994 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -1016,7 +1011,6 @@ async def get_entity():
10161011
10171012
10181013@when ("a new async entity creation fails within an atomic transaction" )
1019- @safe_run_async
10201014async def step_when_async_entity_creation_fails (context ):
10211015 """Attempt to create an async entity with a failure that causes rollback."""
10221016 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -1053,7 +1047,6 @@ async def create_entity_with_failure():
10531047
10541048
10551049@then ("no async entity should exist in the database" )
1056- @safe_run_async
10571050async def step_then_no_async_entity_should_exist (context ):
10581051 """Verify the entity doesn't exist after failed async atomic transaction."""
10591052 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -1075,7 +1068,6 @@ async def check_entity_absence():
10751068
10761069
10771070@then ("the async database session should remain usable" )
1078- @safe_run_async
10791071async def step_then_async_session_should_remain_usable (context ):
10801072 """Verify the async session is still usable after a failed transaction."""
10811073 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -1107,7 +1099,6 @@ async def verify_session_usable():
11071099
11081100
11091101@when ("multiple entities are created in an async atomic transaction" )
1110- @safe_run_async
11111102async def step_when_multiple_async_entities_created (context ):
11121103 """Create multiple entities in a single async atomic transaction."""
11131104 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -1141,7 +1132,6 @@ async def create_multiple_entities():
11411132
11421133
11431134@then ("all async entities should be retrievable" )
1144- @safe_run_async
11451135async def step_then_all_async_entities_retrievable (context ):
11461136 """Verify all entities exist after async atomic transaction."""
11471137 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -1177,7 +1167,6 @@ async def verify_entities():
11771167
11781168
11791169@when ("complex async operations are performed in a transaction" )
1180- @safe_run_async
11811170async def step_when_complex_async_operations (context ):
11821171 """Demonstrate more complex async operations with proper session management."""
11831172 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
@@ -1227,7 +1216,6 @@ async def create_entity_with_relations():
12271216
12281217
12291218@then ("all related entities should be accessible" )
1230- @safe_run_async
12311219async def step_then_related_entities_accessible (context ):
12321220 """Verify that related entities can be accessed through relationships."""
12331221 logger = getattr (context , "logger" , logging .getLogger ("behave.steps" ))
0 commit comments