This has been fixed in pytest-django
's master branch.
You can read about it here
I was able to install it with pip
by issuing the following command -
pip install https://github.com/pytest-dev/pytest-django/zipball/master
Question
Morning, i'm using test inherit from django.test.TestCase and I have problems using setupclass method, because that access to db and and raise this error "Failed: Database access not allowed, use the "django_db" mark to enable", however i'm using the django_db mark. Here is the code:
from django.test import TestCase
@pytest.mark.django_db
class ViewAllBeneficiariesTest(TestCase):
''' Tests for Beneficiary '''
@classmethod
def setUpClass(cls):
cls.u = model_mommy_create_user_permission_all()
def test_clients_view_all_beneficiaries_get_ok(self):
#Arrange:
self.client.login(username=self.u.username, password="admin")
#Act:
res = self.client.get('/clients/beneficiaries/all/')
#Assert:
self.assertEqual(res.status_code, 200)
self.assertTemplateUsed(res, 'clients/search_beneficiaries.html')
def test_clients_view_all_beneficiaries_404(self):
#Arrange:
self.client.login(username=self.u.username, password="admin")
#Act:
res = self.client.get('/clients/beneficiaries/all/')
#Assert:
self.assertEqual(res.status_code, 404)
def test_clients_view_all_beneficiaries_fail(self):
#Arrange:
#Act:
res = self.client.get('/clients/beneficiaries/all/')
#Assert:
self.assertEqual(res.status_code, 302)
self.assertRedirects(res, '/accounts/login/')
Solution
This has been fixed in pytest-django
's master branch.
You can read about it here
I was able to install it with pip
by issuing the following command -
pip install https://github.com/pytest-dev/pytest-django/zipball/master