奈杰尔的回答很好,绝对是进入门槛最低的选择。但是,您可以获得更好django_nose
的反馈(而且设置起来并不难;)。
以下来自:BDD with Python
第一:安装一些要求:
pip install nose pinocchio django_nose
然后将以下内容添加到settings.py
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = ['--with-spec', '--spec-color']
然后正常运行测试:
python manage.py test
输出应如下所示:

注意:测试下的注释可用于提供比名称更好的输出。
例如:
def test_something(self):
"""Something should happen"""
...
运行测试时将输出“应该发生的事情”。
加分项:您还可以生成/输出您的代码覆盖率:
pip install coverage
在 settings.py 中将以下内容添加到您的 NOSE_ARGS 中:'--with-coverage', '--cover-html', '--cover-package=.', '--cover-html-dir=reports/cover'
例如:
NOSE_ARGS = ['--with-spec', '--spec-color',
'--with-coverage', '--cover-html',
'--cover-package=.', '--cover-html-dir=reports/cover']
然后你会在运行时得到一个很好的代码覆盖率摘要python manage.py test
以及一个简洁的 html 报告reports/cover