[英]Django not running tests with manage.py test
I have a problem with Django's test. 我对Django的测试有疑问。 I start this command for running test:
我启动此命令以运行测试:
$ python manage.py test gastrobook
gastrobook is my app, tha comand would be fine for the Django's documentation, in fact it works but don't run nothing test but in tests.py i have written some test! gastrobook是我的应用程序,comand对于Django的文档来说还不错,实际上它可以工作,但是不进行任何测试,但是在tests.py中,我编写了一些测试! This is that terminal say:
这是那个终端说:
$ python manage.py test gastrobook/
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
This is my tests.py 这是我的tests.py
from django.test import TestCase from gastrobook.models import * import datetime from django.utils import timezone # Create your tests here. def create_recipe(title,desc,procedimento,pub_date,hard,time,person): return Recipe.objects.create(title=title,desc=desc,procedimento=procedimento,pub_date=pub_date,hard=hard,time=time,person=person) class RecipeTest(TestCase): def setUp(self): create_recipe("cui","dcnjenj","owcjc",timezone.now(),2,"5 ore",2) def hard_no_more_than(self): recipe = Recipe.objects.all() for rec in recipe: self.assertIn(rec.hard,range(1,10))
from the unittest documentation 从unittest文档中
A testcase is created by subclassing unittest.TestCase.
通过子类化unittest.TestCase创建一个测试用例。 The three individual tests are defined with methods whose names start with the letters
test
.这三个单独的测试使用名称以字母
test
开头的方法定义。 This naming convention informs the test runner about which methods represent tests.该命名约定将告知测试运行者哪些方法表示测试。
change your test function to test_hard_no_more_than
, then the test runner whould be able to discover the testcase. 将您的测试函数更改为
test_hard_no_more_than
,然后可以找到测试用例的测试运行器。
Test methods need to be named starting with "test" for the test runner to find them. 测试方法需要以“ test”开头,以便测试运行者找到它们。 So your method should be called "test_hard_no_more_than".
因此,您的方法应称为“ test_hard_no_more_than”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.