我正在研究Django 1.9 Django 1.9 Tutorial Part 5。
我正在使用Python 2.7.6和Django 1.9.4。 我的文件夹的树结构是:
django-mysite/
├── db.sqlite3
├── manage.py
├── mysite
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── __pycache__
│ │ ├── __init__.cpython-34.pyc
│ │ ├── __init__.cpython-34.sublime-workspace
│ │ ├── settings.cpython-34.pyc
│ │ ├── urls.cpython-34.pyc
│ │ └── wsgi.cpython-34.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
└── polls
├── admin.py
├── admin.pyc
├── apps.py
├── apps.pyc
├── __init__.py
├── __init__.pyc
├── migrations
│ ├── 0001_initial.py
│ ├── 0001_initial.pyc
│ ├── __init__.py
│ └── __init__.pyc
├── models.py
├── models.pyc
├── templates
│ └── polls
│ ├── detail.html
│ ├── index.html
│ ├── results.html
│ └── tests.py
├── tests.py
├── tests.pyc
├── urls.py
├── urls.pyc
├── views.py
└── views.pyc
当我通过命令运行测试时:
python manage.py test polls
或
python manage.py test polls.tests
它没有运行测试。输出是:
Creating test database for alias 'default'...
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
tests.py
文件包含代码(如教程中所示)
import datetime
from django.utils import timezone
from django.test import TestCase
from .models import Question
class QuestionMethodTests(TestCase):
def test_was_published_recently_with_future_question(self):
"""
was_published_recently() should return False for questions whose
pub_date is in the future.
"""
time = timezone.now() + datetime.timedelta(days=30)
future_question = Question(pub_date=time)
self.assertEqual(future_question.was_published_recently(), False)
什么错了?
答案 0 :(得分:2)
从template / polls文件夹中删除tests.py,然后尝试。
要运行测试,请尝试python manage.py test polls