MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / run_test

Method run_test

test/ext/asyncio/test_engine.py:74–175  ·  view source on GitHub ↗
(subject, trans_on_subject, execute_on_subject)

Source from the content-addressed store, hash-verified

72 t.create(eng)
73
74 async def run_test(subject, trans_on_subject, execute_on_subject):
75 async with subject.begin() as trans:
76 if begin_nested:
77 if not config.requirements.savepoints.enabled:
78 config.skip_test("savepoints not enabled")
79 if execute_on_subject:
80 nested_trans = subject.begin_nested()
81 else:
82 nested_trans = trans.begin_nested()
83
84 async with nested_trans:
85 if execute_on_subject:
86 await subject.execute(t.insert(), {"data": 10})
87 else:
88 await trans.execute(t.insert(), {"data": 10})
89
90 # for nested trans, we always commit/rollback on the
91 # "nested trans" object itself.
92 # only Session(future=False) will affect savepoint
93 # transaction for session.commit/rollback
94
95 if rollback:
96 await nested_trans.rollback()
97 else:
98 await nested_trans.commit()
99
100 if run_second_execute:
101 with assertions.expect_raises_message(
102 exc.InvalidRequestError,
103 "Can't operate on closed transaction "
104 "inside context manager. Please complete the "
105 "context manager "
106 "before emitting further commands.",
107 ):
108 if execute_on_subject:
109 await subject.execute(
110 t.insert(), {"data": 12}
111 )
112 else:
113 await trans.execute(
114 t.insert(), {"data": 12}
115 )
116
117 # outside the nested trans block, but still inside the
118 # transaction block, we can run SQL, and it will be
119 # committed
120 if execute_on_subject:
121 await subject.execute(t.insert(), {"data": 14})
122 else:
123 await trans.execute(t.insert(), {"data": 14})
124
125 else:
126 if execute_on_subject:
127 await subject.execute(t.insert(), {"data": 10})
128 else:
129 await trans.execute(t.insert(), {"data": 10})
130
131 if trans_on_subject:

Callers

nothing calls this directly

Calls 13

eq_Function · 0.90
selectFunction · 0.90
skip_testMethod · 0.80
beginMethod · 0.45
begin_nestedMethod · 0.45
executeMethod · 0.45
insertMethod · 0.45
rollbackMethod · 0.45
commitMethod · 0.45
scalarMethod · 0.45
select_fromMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected