django doctests没有运行 [英] django doctests not being run

查看:102
本文介绍了django doctests没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm having a problem running django doctests with django-nose. Unit tests added to a /tests directory are running fine, but doctests are not.

我正在尝试在季节"模块上运行doctest:

I am trying to run doctests on my "season" module:

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来尝试使其工作,例如:

I'm just trying a basic doctest to try to get this to work, e.g.:

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

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

This is in my models.py. I've tried other doctests actually testing the code and still don't see any tests run. When I run with --verbosity 3, I see one line that may be the issue:

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

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

I couldn't find any more info on what this means though.

settings.py中的相关片段:

Relevant snippets from settings.py:

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

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

django_nose在django-nose文档中指定的INSTALLED_APPS中位于南方之后.我使用的是此处建议的--with-doctest参数:鼻子没有运行Django doctests ,并按照此处的建议将django-nose更新为最新版本:

django_nose is after south in INSTALLED_APPS as specified in the django-nose documentation. I'm using the --with-doctest argument as suggested here: Nose not running Django doctests, and have updated my django-nose to the latest as suggested here: Why isn't django-nose running the doctests in my models?

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

These are the versions I am using:
django 1.3
python 2.7.1
django-nose 0.1.3
nose 1.1.2

我觉得这里缺少一些基本设置.让我知道是否需要其他信息.感谢您的任何帮助,谢谢!

I feel like I'm missing some basic setup here. Let me know if any other info is needed. Any help is appreciated, thanks!

推荐答案

我意识到OP指定了1.3,但由于此答案是在搜索"django doctests not run"时出现的,因此这是我对1.6的答案之一 Django doctests中的答案.在此版本的Django doctest中会自动包含 ,因此在$ APP/tests.py中,您需要:

I realize that the OP specified 1.3, but since this answer comes up in a search for 'django doctests do not run' here's my answer for 1.6 from one of the answers in Django doctests in views.py. in this version of Django doctests are not automatically included, so in $APP/tests.py you need:

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

[这只能在tests.py本身中找到doctest;要使其在其他模块(例如myapp/models.py)上运行doctest,您需要from myapp import modelstests.addTests(doctest.DocTestSuite(models))]

[this only finds the doctests in tests.py itself; to have it run doctests on other modules, say myapp/models.py, you need to from myapp import models and tests.addTests(doctest.DocTestSuite(models))]

这篇关于django doctests没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆