Hello,
I am using TestCase and trying to create an object during test.
There is a log activated on MySQL server, so I see all the queries being
executed there.
This "transaction.atomic" sets a SAVEPOINT in the database thinking that
the transaction is already started. The problem is that there
I don't think the subclass of TestCase need to use transaction.atomic. Why
can't you just remove the transaction.atomic?
Regards,
Aldian Fazrihady
http://aldianfazrihady.com
Pada tanggal Sel, 12 Mei 2020 04.02, Uri Kogan menulis:
> Hello,
>
> I am using TestCase and trying to create an object
While this can be done in my code, there are libraries that the project use
that have "transaction.atomic" in them. For example, pretty popular
django-role-permissions.
>From what I see in the documentation, there should be no problem to use
transactions within transactions in TestCase.
On Tues
When testing django apps, my unit test usually accesses the django app via
django test client:
https://docs.djangoproject.com/en/3.0/topics/testing/tools/#the-test-client.
Django test client simulates http access, so my Django tests always run my
Django code starting from Django views.
Even though
That not that simple in my case because. I'll show what I mean:
from django.contrib.auth.models import User
from django.test import TestCase
from rolepermissions.roles import assign_role
class FooTest(TestCase):
def test_bar(self):
u = User.objects.create_user(username="abc", password
Probably you need to use TransactionTestCase, which is the parent of
TestCase instead:
https://docs.djangoproject.com/en/3.0/topics/testing/tools/#transactiontestcase
That page also mentions a specific problem when using transaction on
TestCase:
```
A consequence of this, however, is that some data
The documentation states that "you cannot test that a block of code is
executing within a transaction" while I am looking to "test a block of code
that has a transaction".
In any case, the issue here is that "transaction.atomic" does not work when
nested while it should clearly work.
On Tuesday
Continuing my investigation I got the a following which does not work but
should:
from django.contrib.auth.models import User
from django.test import TransactionTestCase
from django.db import transaction
class FooTest(TransactionTestCase):
def test_bar(self):
with transaction.atomic()
8 matches
Mail list logo