On Friday, March 7, 2014 12:11:59 AM UTC+2, Justin Michalicek wrote:
>
> It appears that due to test cases running in an atomic block, testing 
> methods which use transaction.set_autocommit() all fail.  I've got a small 
> handful of test cases around methods which need to use manual transaction 
> management and they are definitely working when I actually use the site, 
> but in test cases they all fail and raise the exception 
> "TransactionManagementError: This is forbidden when an 'atomic' block is 
> active." at the line where I call transaction.set_autocommit(False)
>
> Is there something I'm missing here?
>

Django's default TestCase runs the whole test inside a transaction, thus 
code trying to manage transactions fail. The reason for this is that if the 
tests are ran inside transactions, there is no need to clean up the 
database after the test, as doing rollback at the end of the test will 
guarantee clean state. If you need to test transactional code, use 
TransactionTestCase.

 - Anssi 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80596e57-ec2f-44c7-bd89-2eb2990d2d3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to