How do you test code that disables autocommit and uses savepoints, inside a Django unittest?
The default Django unittest class wraps all tests inside an @atomic
decorator, which is usually exactly what you want, to ensure the sqlite database gets reset between tests. However, any code that touches transaction.set_autocommit()
from a test throws the error:
TransactionManagementError: This is forbidden when an 'atomic' block is active.
even if it works fine outside the unittest.
How do you temporarily disable the transaction autocommit in a unittest, so you can test manual commits?