6

我在使用 django-nose 运行 django doctests 时遇到问题。添加到 /tests 目录的单元测试运行良好,但 doctests 不是。

我正在尝试在我的“季节”模块上运行文档测试:

python manage.py test season

并得到这个输出:

nosetests --verbosity 1 season --with-doctest
Creating test database for alias 'default'...

----------------------------------------------------------------------
Ran 0 tests in 0.001s

OK
Destroying test database for alias 'default'...

我只是在尝试一个基本的 doctest 来尝试让它工作,例如:

    """
    >>> 1+1 == 2
    True
    """

这是在我的models.py 中。我已经尝试过其他 doctests 实际测试代码,但仍然没有看到任何测试运行。当我使用 --verbosity 3 运行时,我看到一行可能是问题所在:

nose.selector: INFO: <models.py path> is executable; skipped

我找不到更多关于这意味着什么的信息。

来自 settings.py 的相关片段:

INSTALLED_APPS = (
    'south',
    'django_nose',
    'season',
)

# Django-nose configuration
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = ['--with-doctest']

django_nose 在 INSTALLED_APPS 中位于南之后,如 django-nose 文档中所指定。我正在使用此处建议的 --with-doctest 参数:Nose not running Django doctests,并已按照此处的建议将我的 django-nose 更新到最新版本:Why is django-nose running the doctests in my models?

这些是我正在使用的版本:
django 1.3
python 2.7.1
django-nose 0.1.3
nose 1.1.2

我觉得我在这里缺少一些基本设置。让我知道是否需要任何其他信息。任何帮助表示赞赏,谢谢!

4

3 回答 3

4

我意识到 OP 指定了 1.3,但是由于这个答案是在搜索“django doctests do not run”时出现的,所以这是我对 1.6 的答案,来自views.py 中 Django doctests的答案之一。在这个版本的 Django 文档测试中没有自动包含,所以在 $APP/tests.py 你需要:

import doctest
def load_tests(loader, tests, ignore):
    tests.addTests(doctest.DocTestSuite())
    return tests

[这只会在 tests.py 本身中找到文档测试;让它在其他模块上运行 doctests,比如 myapp/models.py,你需要from myapp import modelstests.addTests(doctest.DocTestSuite(models))]

于 2014-04-11T23:45:11.133 回答
2

详细信息告诉您您的 models.py 文件被忽略,因为它是可执行的。这意味着您需要执行以下操作:

chmod -x models.py

除非您有特定原因将该文件设置为可执行文件,否则添加--exe到您的文件NOSE_ARGS就足够了。

于 2013-03-13T00:12:42.430 回答
1

nosetests --verbosity 1 season --with-doctest

Usage: manage.py test [options] [appname ...]

也许你只需要移动season到那时结束。

于 2011-10-16T20:53:09.783 回答