2
我在使用Django测试套件时遇到了一个小问题。Django和docfiles中的测试
我正在研究可以在Django和Plone(http://pypi.python.org/pypi/jquery.pyproxy)中运行的Python包。 所有的测试都是作为doctests编写的,无论是在Python代码中还是在单独的docfiles中(例如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),
}
我想我做错了什么时候声明测试su但我不知道它到底是什么。调用doctest.testfile或doctest.testmod的是,测试时
import os
import doctest
from django.utils import unittest
from jquery.pyproxy import base, utils
OPTIONFLAGS = (doctest.ELLIPSIS |
doctest.NORMALIZE_WHITESPACE)
testmods = {'base': base,
'utils': utils}
testfiles = {'readme': '../../../README.rst',
'django': 'django.txt'}
def suite():
return unittest.TestSuite(
[doctest.DocTestSuite(mod, optionflags = OPTIONFLAGS)
for mod in testmods.values()] + \
[doctest.DocFileSuite(f, optionflags = OPTIONFLAGS)
for f in testfiles.values()])
显然的问题:
感谢您的帮助, 文森特
不要把“我终于解决了......”放在问题中。删除这个。创建一个答案。如果您解决了这个问题,您必须发布您的解决方案作为答案。将答案发布为答案而不是延续问题要好得多。 –
这就是我第一次尝试,但直到几个小时才回答我自己的问题。我会尽可能更新。 – Vincent