2014-10-05 107 views
2

測試我有Django的測試問題。我開始這個命令來運行測試:Django沒有運行與manage.py測試

$ 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)) 
+0

什麼是您的Django版本? – Zulu 2014-10-05 11:35:24

+0

你可以嘗試沒有結尾的斜線('/')嗎?你必須指定一個Python模塊(帶點('.')作爲分隔符)而不是目錄。 – Zulu 2014-10-05 11:42:22

回答

3
unittest documentation

測試用例

由子類創建unittest.TestCase生成。三個單獨的測試用名稱以字母test開頭的方法定義。這個命名約定告訴測試運行者哪些方法代表測試。

將您的測試功能更改爲test_hard_no_more_than,然後測試運行者能夠發現測試用例。

1

試驗方法需要在開始與「測試」被命名爲測試運行,以找到他們。所以你的方法應該被稱爲「test_hard_no_more_than」。