2012-09-20 86 views
1

我有以下型号为什么Django-nose运行两次?

class Poll(models.Model): 

    question = models.CharField(max_length=200) 
    pub_date = models.DateTimeField(auto_now_add=True) 

    def __unicode__(self): 
      return self.question 

及以下测试

from polls.models import Poll 
from django.test import TestCase 
from django.utils import timezone 

class PollModelTest(TestCase): 

    def test_poll_save(self): 
     q = "What is the best OS?" 
     pd = timezone.now() 
     p = Poll(question=q, 
       pub_date=pd) 
     p.save() 
     polls = Poll.objects.all() 
     self.assertEquals(polls.count(), 1) 
     self.assertEquals(polls[0].question, q) 

及以下设置

INSTALLED_APPS = (
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    # Uncomment the next line to enable the admin: 
    'django.contrib.admin', 
    # Uncomment the next line to enable admin documentation: 
    # 'django.contrib.admindocs', 
    'polls', 
    'django_nose', 

) 

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' 
NOSE_ARGS = [ 
    '--with-coverage', 
    '--cover-package=polls', 
    '--with-progressive', 
    '--verbosity=0', 
    '--with-fixture-bundling', 
] 

当我尝试python manage.py test polls测试s 运行两次。以下是输出:

Creating test database for alias 'default'... 
Name   Stmts Miss Cover Missing 
-------------------------------------------- 
polls    0  0 100% 
polls.models  6  0 100% 
-------------------------------------------- 
TOTAL    6  0 100% 

OK! 2 tests, 0 failures, 0 errors in 0.0s 
Destroying test database for alias 'default'... 

然而,当我尝试没有TEST_RUNNER = 'django_nose.NoseTestSuiteRunner',则测试运行只有一次。以下是输出:

Creating test database for alias 'default'... 
. 
---------------------------------------------------------------------- 
Ran 1 test in 0.002s 

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

请告诉我什么是错? 为什么django-nose运行两次测试?

OT:django_nose需要更多的时间比单元测试,在相同的模型。

编辑:

这里的文件夹结构:

├── database.sqlite 
├── manage.py 
├── mysite 
│   ├── __init__.py 
│   ├── settings.py 
│   ├── templates 
│   │   ├── 404.html 
│   │   ├── 500.html 
│   │   └── base.html 
│   ├── urls.py 
│   └── wsgi.py 
└── polls 
    ├── __init__.py 
    ├── models.py 
    ├── tests 
    │   ├── __init__.py 
    │   └── test_models.py 
    ├── urls.py 
    └── views.py 

回答

2

也许你有你的测试进口的两倍。你没有显示你的文件结构,但也许你在单独的文件中有这个测试,并且你在tests.py中做了import,或者类似的东西。

+0

更新了文件夹结构,请检查! – user1629366

+0

@ user1629366那你在'polls/tests/__ init __。py'中有什么?你在那里导入test_models? – yakxxx

+0

'从test_models导入*'多数民众赞成它。 – user1629366

相关问题