繁体   English   中英

Django不使用manage.py测试运行测试

[英]Django not running tests with manage.py test

我对Django的测试有疑问。 我启动此命令以运行测试:

$ python manage.py test gastrobook

gastrobook是我的应用程序,comand对于Django的文档来说还不错,实际上它可以工作,但是不进行任何测试,但是在tests.py中,我编写了一些测试! 这是那个终端说:

$ python manage.py test gastrobook/
Creating test database for alias 'default'...

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
Destroying test database for alias 'default'...

这是我的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)) 

unittest文档中

通过子类化unittest.TestCase创建一个测试用例。 这三个单独的测试使用名称以字母test开头的方法定义。 该命名约定将告知测试运行者哪些方法表示测试。

将您的测试函数更改为test_hard_no_more_than ,然后可以找到测试用例的测试运行器。

测试方法需要以“ test”开头,以便测试运行者找到它们。 因此,您的方法应称为“ test_hard_no_more_than”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM