为什么当我运行一项测试时它通过了,但是当我运行所有测试时,它却掉了

时间:2019-04-22 13:07:22

标签: python django django-admin django-unittest

我在django项目中为管理员界面编写了测试,并且所有测试都分别通过,但是当我运行带有测试的类时,它将失败。

带有测试的类(test_admin.py):

from django.forms.models import model_to_dict
from django.test import TestCase
from core.tests.test_data import TestDataAbs

from apps.doctor.models import Doctor, DoctorSchedule, DoctorSpecialization
import apps.doctor.admin as admin_models

OK_STATUS_CODE = 200


class TestAdmin(TestCase, TestDataAbs):
    def setUp(self):
        self.test_root_user = self.root_user 
        self.client.login(username=self.root_user_test_data['username'], password=self.root_user_test_data['password'])

def tearDown(self):
    self.client.logout()

def test_add_doctor(self):
    admin_tickets_pages = TestDataAbs.get_admin_urls('doctor', admin_models)
    self.client.post(admin_tickets_pages['doctor_add'],
                     data=model_to_dict(Doctor.get_first_or_create()))
    response = self.client.get(admin_tickets_pages['doctor_change'])
    self.assertEqual(response.status_code, OK_STATUS_CODE)

def test_add_doctor_specialization(self):
    admin_tickets_pages = TestDataAbs.get_admin_urls('doctor', admin_models)
    self.client.post(admin_tickets_pages['doctorspecialization_add'],
                     data=model_to_dict(DoctorSpecialization.get_first_or_create()))
    response = self.client.get(admin_tickets_pages['doctorspecialization_change'])
    self.assertEqual(response.status_code, OK_STATUS_CODE)

def test_add_doctor_schedule(self):
    admin_tickets_pages = TestDataAbs.get_admin_urls('doctor', admin_models)
    self.client.post(admin_tickets_pages['doctorschedule_add'],
                     data=model_to_dict(DoctorSchedule.get_first_or_create()))
    response = self.client.get(admin_tickets_pages['doctorschedule_change'])
    self.assertEqual(response.status_code, OK_STATUS_CODE)

运行一项测试:

使用测试运行类: enter image description here

0 个答案:

没有答案