Skip to main content

TestCase

Similar to TransactionTestCase, but use transaction.atomic() to achieve test isolation.

Attributes

AttributeTypeDescription
cls_atomicsdictDictionary mapping database names to their respective atomic transaction blocks opened at the class level for test isolation.
atomicsdictDictionary mapping database names to their respective atomic transaction blocks opened for an individual test method.

Methods


setUpClass()

@classmethod
def setUpClass()

Prepares the class-level test environment by opening transactions, loading fixtures, and initializing test data.


tearDownClass()

@classmethod
def tearDownClass()

Cleans up the class-level test environment by rolling back transactions and closing database connections.


setUpTestData()

@classmethod
def setUpTestData()

Load initial data for the TestCase.


captureOnCommitCallbacks()

@classmethod
def captureOnCommitCallbacks(
using: str,
execute: bool
) - > list

Context manager to capture transaction.on_commit() callbacks.

Parameters

NameTypeDescription
usingstrThe database alias to monitor for on_commit callbacks
executeboolWhether to immediately invoke the captured callbacks upon exiting the context

Returns

TypeDescription
listA list that will be populated with the captured callback functions