MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / run_test

Method run_test

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

Source from the content-addressed store, hash-verified

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