質問

I have the following models:

class Poll(models.Model):

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

    def __unicode__(self):
             return self.question

and the following test

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)

and the following settings:

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',
] 

When I try python manage.py test polls the tests run twice. Following is the output:

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'...

However when I try without TEST_RUNNER = 'django_nose.NoseTestSuiteRunner', then the tests runs only once. Following is the output:

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

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

Please tell me what is wrong? Why is django-nose running tests twice?

OT: django_nose takes more time than unittest, for the same model.

EDIT:

Here is the folder structure:

├── 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
役に立ちましたか?

解決

Probably You have Your tests imported twice. You didn't show your file structure, but maybe You have this test in separate file and than you do import in tests.py, or something like that.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top