为什么我在终端中运行python manage.py test appname
是:在0.000s内运行0个测试
这是我的测试.py公司名称:
from django.test import TestCase
import appname.factories
class UserProfileTest(TestCase):
def sample_data(self):
for i in range(0, 10):
user = appname.factories.UserProfileFactory.create()
我的模型.py公司名称:
^{pr2}$我的工厂.py(工厂男孩):
from appname.models import *
import factory
class UserProfileFactory(factory.Factory):
FACTORY_FOR = UserProfile
street = factory.Sequence(lambda n: 'Street' + n)
tel = factory.Sequence(lambda n: 'Tel' + n)
password = 'abcdef'
你的个人测试功能应该以单词“test”开头。在
您需要将函数
def sample_data(self):
更改为def test_sample_data(self):
测试运行程序将在名为
tests.py
的文件中查找任何类,这些类位于应用程序的根目录中,并扩展unittest.TestCase
。然后它将运行该类中以单词test开头的任何函数(加上一个或两个其他函数,如setup()
)我可能有点迟钝,但我在main django testing docs中看不到任何关于函数必须以单词test开头的内容。无论如何,在this(官方)教程中有一个对该需求的引用。在
test.py
错误,应该是tests.py
说docs about writing tests:
相关问题 更多 >
编程相关推荐