0
我正在通過Django 1.9 Django 1.9 Tutorial Part 5工作。Django 1.9教程:沒有測試運行
我使用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)
的哪些錯誤?
爲什麼你需要在你的'templates'文件夾中的'tests.py'?也許這是造成問題的原因。 – sehrob
如何運行'python manage.py測試民意測驗'?它運行嗎? –
@sehrob很好的捕獲。我使用Sublime Text(文件夾視圖)在/ polls文件夾中創建一個新的.py文件。它在嵌套文件夾中也創建了相同的文件。奇怪。非常感謝。 –