【发布时间】:2014-10-05 11:29:32
【问题描述】:
我对 Django 的测试有疑问。我启动这个命令来运行测试:
$ python manage.py test gastrobook
gastrobook 是我的应用程序,对于 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))
【问题讨论】:
-
你的 Django 版本是多少?
-
你可以试试不带斜杠 (
/) 吗?您必须指定 Python 模块(以点 (.) 作为分隔符)而不是目录。
标签: python django unit-testing testing