Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python setupclass中django_db标记存在问题_Python_Django_Testing_Django Database - Fatal编程技术网

Python setupclass中django_db标记存在问题

Python setupclass中django_db标记存在问题,python,django,testing,django-database,Python,Django,Testing,Django Database,早上好,我正在使用test inherit from django.test.TestCase,我在使用setupclass方法时遇到问题,因为对db的访问并引发此错误“Failed:Database access not allowed,请使用“django_db”标记启用”,但我使用的是django_db标记。代码如下: from django.test import TestCase @pytest.mark.django_db class ViewAllBeneficiariesTes

早上好,我正在使用test inherit from django.test.TestCase,我在使用setupclass方法时遇到问题,因为对db的访问并引发此错误“Failed:Database access not allowed,请使用“django_db”标记启用”,但我使用的是django_db标记。代码如下:

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/')

这已在pytest django的主分支中修复

你可以读到它

通过发出以下命令,我可以使用
pip
安装它-

pip install https://github.com/pytest-dev/pytest-django/zipball/master

这是你来源的实际缩进吗?不,这是给复制的缩进。对不起,我想我会在这里重构代码……完成,代码重构;)