I am trying to run the following Django unittest:
class MyModelTests(TestCase): def test_failed_duplicate(self): m = MyModel.objects.create(a='a', b='a') with self.assertRaises(IntegrityError): MyModel.objects.create(a='a', b='b') with self.assertRaises(IntegrityError): MyModel.objects.create(a='a', b='c') with self.assertRaises(IntegrityError): MyModel.objects.create(a='a', b='d')
There are several tests that should fail due to a violation of the uniqueness constraint in field a . (I am a bit confused about the statements, but they all test different values โโof a , which should fail.)
However, at startup, I get:
Traceback (most recent call last): File "...", line 21, in test_failed_duplicate MyModel.objects.create(a='a', b='c') TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
What am I missing?
source share