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

Method run_test

lib/sqlalchemy/testing/fixtures/base.py:265–382  ·  view source on GitHub ↗
(subject, trans_on_subject, execute_on_subject)

Source from the content-addressed store, hash-verified

263 t.create(eng)
264
265 def run_test(subject, trans_on_subject, execute_on_subject):
266 with subject.begin() as trans:
267 if begin_nested:
268 if not config.requirements.savepoints.enabled:
269 config.skip_test("savepoints not enabled")
270 if execute_on_subject:
271 nested_trans = subject.begin_nested()
272 else:
273 nested_trans = trans.begin_nested()
274
275 with nested_trans:
276 if execute_on_subject:
277 subject.execute(t.insert(), {"data": 10})
278 else:
279 trans.execute(t.insert(), {"data": 10})
280
281 # for nested trans, we always commit/rollback on the
282 # "nested trans" object itself.
283 # only Session(future=False) will affect savepoint
284 # transaction for session.commit/rollback
285
286 if rollback:
287 nested_trans.rollback()
288 else:
289 nested_trans.commit()
290
291 if second_operation != "none":
292 with assertions.expect_raises_message(
293 sa.exc.InvalidRequestError,
294 "Can't operate on closed transaction "
295 "inside context "
296 "manager. Please complete the context "
297 "manager "
298 "before emitting further commands.",
299 ):
300 if second_operation == "execute":
301 if execute_on_subject:
302 subject.execute(
303 t.insert(), {"data": 12}
304 )
305 else:
306 trans.execute(t.insert(), {"data": 12})
307 elif second_operation == "begin":
308 if execute_on_subject:
309 subject.begin_nested()
310 else:
311 trans.begin_nested()
312
313 # outside the nested trans block, but still inside the
314 # transaction block, we can run SQL, and it will be
315 # committed
316 if execute_on_subject:
317 subject.execute(t.insert(), {"data": 14})
318 else:
319 trans.execute(t.insert(), {"data": 14})
320
321 else:
322 if execute_on_subject:

Callers

nothing calls this directly

Calls 13

selectFunction · 0.90
eq_Function · 0.85
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