Django测试员没有找到测试 [英] Django test runner not finding tests

查看:130
本文介绍了Django测试员没有找到测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Python和Django的新手,我正在通过创建一个饮食管理网站来学习,但是通过让我的单元测试运行,我完全失败了。我发现所有的文档和博客都表示,只要从tests.py可以发现,tests.py与models.py和测试类子类TestCase在同一个文件夹中,所有这些文件和博客都应该被自动拾取。这不适用于我,当我运行 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆