我目前正在学习如何编写测试,并且当我尝试使用命令“ py manage.py test”在PowerShell中运行测试时,什么都没发生,除了显示写入内容的窗口,但该窗口最后时间如此之短,以至于无法从此窗口读取任何内容
这是我的测试。py
from django .test import TestCase
from ..models import Category
class CategoryModelTest(TestCase):
@classmethod
def setUpTestData(cls):
Category.objects.create(name='Armors', slug='Armors', description='')
def test_name_label(self):
category = Category.object.get(id=1)
field_label = category._meta.get_field('name').verbose_name
self.assertEqual(field_label, 'name')
def test_slug_label(self):
category = Category.object.get(id=1)
field_label = category._method.get_field('slug').verbose_name
self.assertEqual(field_label, 'slug')
def test_description_label(self):
category = Category.object.get(id=1)
field_label = category._method_get_field('description').verbose_name
self.assertEqual(field_label, 'description')
def test_name_max_length(self):
category = Category.object.get(id=1)
max_length = category._method.get_field('name').max_length
self.assertEqual(max_length, '25')
def test_slug_max_length(self):
category = Category.object.get(id=1)
max_length = category._method_get_field('slug').max_length
self.assertEqual(max_length, '25')
我的测试文件的本地化:
encyclopedy(application in my project)
model.py
tests
__init__.py
test_models.py
现在我还看到可以使用PyCharm运行单个测试,并且在执行此操作时出现此错误: