Django测试员没有找到测试 [英] Django test runner not finding tests
问题描述
manage.py test< myapp>
它没有找到任何测试。 我以自己的包中的所有测试开始,但将其简化为只在我的tests.py文件中的所有测试。当前的tests.py看起来像:
import unittest
from pyDietTracker.models import Weight
from pyDietTracker .weight.DisplayDataAdapters import DisplayWeight
class TestDisplayWeight(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testGetWeightInStone_KG_Correctly_Converted(self):
weight = Weight()
weight.weight = 99.8
testAdapter = DisplayWeight(weight)
self.assertEquals(testAdapter.GetWeightInStone(),'15 st 10 lb')
我已经尝试通过对Django TestCase类进行子类化,但是这也没有。我正在使用Django 1.1.1,Python 2.6和我正在运行Snow Leopard。
我确信我缺少一些非常基本和明显的东西,但我只是可以不了解什么。任何想法?
编辑:只是一个评论后的快速更新
INSTALLED_APPS =(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites ',
'django.contrib.admin',
'pyDietTracker',
)
要运行测试我正在运行 manage.py test pyDietTracker
使用它。
原来我已经做了 django-admin.py startproject pyDietTracker
而不是 python manage.py startapp myApp
。回去做之后,它的工作正如文件所示。看来我有很多东西可以学习阅读,以及Django中网站和应用程序的区别。
感谢您的帮助S.Lott和EmilStenström。我希望我可以接受你的答案,因为他们都被帮助很多。
最重要的课程测试只适用于应用级别而不是站点级别
I am new to both Python and Django and I'm learning by creating a diet management site but I've been completely defeated by getting my unit tests to run. All the docs and blogs I've found say that as long as it's discoverable from tests.py, tests.py is in the same folder as models.py and your test class subclasses TestCase, it should all get picked up automatically. This isn't working for me, when I run manage.py test <myapp>
it doesn't find any tests.
I started with all my tests in their own package but have simplified it down to all tests just being in my tests.py file. The current tests.py looks like:
import unittest
from pyDietTracker.models import Weight
from pyDietTracker.weight.DisplayDataAdapters import DisplayWeight
class TestDisplayWeight(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def testGetWeightInStone_KG_Correctly_Converted(self):
weight = Weight()
weight.weight = 99.8
testAdapter = DisplayWeight(weight)
self.assertEquals(testAdapter.GetWeightInStone(), '15 st 10 lb')
I have tried it by subclassing the Django TestCase class as well but this didn't work either. I'm using Django 1.1.1, Python 2.6 and I'm running Snow Leopard.
I'm sure I am missing something very basic and obvious but I just can't work out what. Any ideas?
Edit: Just a quick update after a comment
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'pyDietTracker',
)
To get the tests to run I am running manage.py test pyDietTracker
Worked it out.
It turns out I had done django-admin.py startproject pyDietTracker
but not python manage.py startapp myApp
. After going back and doing this, it did work as documented. It would appear I have a lot to learn about reading and the difference between a site and an app in Django.
Thank you for your help S.Lott and Emil Stenström. I wish I could accept both your answers because they are both helped alot.
Most important lesson Tests only work at the app level not the site level
这篇关于Django测试员没有找到测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!