diff options
| author | Adam Johnson <me@adamj.eu> | 2020-05-20 11:04:36 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-07-13 11:56:46 +0200 |
| commit | e906ff6fca291fc0bfa0d52f05817ee9dae0335d (patch) | |
| tree | 23f2d6788f6fb7b95b9bb3809f4c48138910373f /docs/topics/db | |
| parent | ca6c5e5fc23f2855a7094d195f09975b21a7ec3f (diff) | |
Fixed #30457 -- Added TestCase.captureOnCommitCallbacks().
Diffstat (limited to 'docs/topics/db')
| -rw-r--r-- | docs/topics/db/transactions.txt | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/docs/topics/db/transactions.txt b/docs/topics/db/transactions.txt index 3eace66c83..996dd7534d 100644 --- a/docs/topics/db/transactions.txt +++ b/docs/topics/db/transactions.txt @@ -394,9 +394,19 @@ Use in tests Django's :class:`~django.test.TestCase` class wraps each test in a transaction and rolls back that transaction after each test, in order to provide test isolation. This means that no transaction is ever actually committed, thus your -:func:`on_commit` callbacks will never be run. If you need to test the results -of an :func:`on_commit` callback, use a -:class:`~django.test.TransactionTestCase` instead. +:func:`on_commit` callbacks will never be run. + +You can overcome this limitation by using +:meth:`.TestCase.captureOnCommitCallbacks`. This captures your +:func:`on_commit` callbacks in a list, allowing you to make assertions on them, +or emulate the transaction committing by calling them. + +Another way to overcome the limitation is to use +:class:`~django.test.TransactionTestCase` instead of +:class:`~django.test.TestCase`. This will mean your transactions are committed, +and the callbacks will run. However +:class:`~django.test.TransactionTestCase` flushes the database between tests, +which is significantly slower than :class:`~django.test.TestCase`\'s isolation. Why no rollback hook? --------------------- |
