我的 Django 测试套件有一个小问题。
我正在开发一个可以在 Django 和 Plone (http://pypi.python.org/pypi/jquery.pyproxy) 中运行的 Python 包。所有测试都以 doctest 的形式编写,无论是在 Python 代码中还是在单独的 docfile(例如 README.txt)中。
我可以让这些测试运行良好,但 Django 只是不计算它们:
[vincent ~/buildouts/tests/django_pyproxy]> bin/django test pyproxy
...
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
但如果我有一些失败的测试,它会正确显示:
[vincent ~/buildouts/tests/django_pyproxy]> bin/django test pyproxy
...
Failed example:
1+1
Expected nothing
Got:
2
**********************************************************************
1 items had failures:
1 of 44 in README.rst
***Test Failed*** 1 failures.
Creating test database for alias 'default'...
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
这就是我的测试套件现在声明的方式:
import os
import doctest
from unittest import TestSuite
from jquery.pyproxy import base, utils
OPTIONFLAGS = (doctest.ELLIPSIS |
doctest.NORMALIZE_WHITESPACE)
__test__ = {
'base': doctest.testmod(
m=base,
optionflags=OPTIONFLAGS),
'utils': doctest.testmod(
m=utils,
optionflags=OPTIONFLAGS),
'readme': doctest.testfile(
"../../../README.rst",
optionflags=OPTIONFLAGS),
'django': doctest.testfile(
"django.txt",
optionflags=OPTIONFLAGS),
}
我想我在声明测试套件时做错了,但我不知道它到底是什么。
谢谢你的帮助,文森特