2013-10-28 14 views
5

Zbudowałem aplikację Django i utworzyłem pakiet z numerem setuptools. Teraz chciałbym zrobić następujące rzeczy:Uruchamianie testu Django z testem setup.py i tox

  1. Chciałbym uruchomić wszystkie testy z python setup.py test. Ale kiedy wydać polecenie, otrzymuję:

    /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. Chciałbym użyć Tox uruchomić moje testy, ale nie mam pojęcia, co mam napisać w atrybucie command uruchomić moich testów aplikacji Django.

Odpowiedz

2

w setup.py:

test_suite = "test_project.runtests.runtests", 

A potem w swoim projekcie:

#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() 

Zobacz this tutorial by Eric Holscher.

+0

Dziękuję wróg pomaga! – linkyndy

+0

Eric Holscher's tutorial jest nieaktualny - zobacz http://gremu.net/blog/2010/enable-setuppy-test-your-django-apps/ – jwhitlock

+0

@jwhitlock twój link jest zepsuty – Saeed

Powiązane problemy