2013-10-28 65 views
5

我构建了一个Django应用程序并使用setuptools制作了一个包。现在,我想做以下事情:使用setup.py测试运行Django测试和tox

  1. 我想用python setup.py test运行所有测试。但是,当我发出这个命令时,我得到:

    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires' 
    warnings.warn(msg) 
    usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] 
    or: setup.py --help [cmd1 cmd2 ...] 
    or: setup.py --help-commands 
    or: setup.py cmd --help 
    
    error: invalid command 'test' 
    
  2. 我想用弓形体运行我的测试,但我不知道我应该在command属性写入运行我的Django应用程序的测试。

回答

2

setup.py

test_suite = "test_project.runtests.runtests", 

然后在你的项目中:

#This file mainly exists to allow python setup.py test to work. 
import os, sys 
os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings' 
test_dir = os.path.dirname(__file__) 
sys.path.insert(0, test_dir) 

from django.test.utils import get_runner 
from django.conf import settings 

def runtests(): 
    test_runner = get_runner(settings) 
    failures = test_runner([], verbosity=1, interactive=True) 
    sys.exit(failures) 

if __name__ == '__main__': 
    runtests() 

this tutorial by Eric Holscher.

+0

谢谢敌我帮助! – linkyndy

+0

Eric Holscher的教程已过时 - 请参阅http://gremu.net/blog/2010/enable-setuppy-test-your-django-apps/ – jwhitlock

+0

@jwhitlock您的链接已损坏 – Saeed