2010-06-12 2 views
1

django.contrib.auth과 같은 설치된 앱에서 ./manage.py test 테스트를 실행하지 못하게 할 방법이 있습니까? lazerscience 말했듯이Django가 contrib 테스트를 실행하지 못하게 하시겠습니까?

+0

IIRC'django.contrib'가 디렉토리가 아닌 응용 프로그램입니다. 이 디렉토리에는 어떤 테스트가 있습니까? –

+3

당신은'./manage.py test appname'을 실행할 수 있습니다. –

+0

@ S.Lott 적어도 실행 중에'test_current_site_in_context_after_login (django.contrib.auth.tests.views.LoginTest)'에 실패했습니다. /manage.py 테스트 '. –

답변

0

음 적절한 솔루션입니다 :

INSTALLED_APPS에서 방금 run test command 모든 응용 프로그램 (예 등 인증, 관리, 사이트 등)의 contrib에서 포함하여 테스트 할
python manage.py test appname appname.SomeTestCase appname.TestCase.test_method 

.

또한 일부 테스트가 실패하면 제대로 작동하지 않는다는 것을 의미하므로 문제를 해결하고 실패한 테스트를 숨겨야합니다. Django 테스트가 실패하면 안정 버전을 사용하고 있는지 확인하십시오.

+0

lazerscience에 답한대로 : 즉, 내 사이트의 맞춤 애플리케이션 10 개를 한 번에 모두 테스트하는 것이 더 쉽지는 않습니다. ( –

1

내가 프로젝트 트리를 걸어, 수입 모든 모듈, unittest.TestCase의 서브 클래스를 찾고 각 모듈에서 클래스를 반복하고있는 TestSuite에 모두 추가 내 프로젝트에 대한 사용자 정의 테스트 러너를 쓰고 있어요, 그들을 실행합니다. 이 방법은, 내가 django.contrib의 사람을 필터링 할 수 있습니다, 또한 나는 단지 무시를 manage.py를 내 자신의 unittest.TestCases (그들은 MyApp를/tests.py에 있지 않기 때문에, 등)의 일부

포함 쓴과 오류의 의심 할 여지없이 가득하지만, 지금까지,이처럼 보이는 것입니다 :

from inspect import getmembers, isclass 
import os 
from os.path import join, relpath 
import sys 
from unittest import TestCase, TestLoader, TestSuite, TextTestRunner 

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' 
from django.test.utils import setup_test_environment 

sys.path.append('..') 


def import_module(modname): 
    print modname 
    try: 
     __import__(modname) 
     return sys.modules[modname] 
    except Exception as e: 
     print 
     print ' %s: %s' % (type(e).__name__, e) 


def get_modules(root): 
    for subdir, dirs, fnames in os.walk(root): 
     for fname in fnames: 
      if fname.endswith('.py'): 
       path = relpath(join(subdir, fname)) 
       modname = path.replace('/', '.')[:-3] 
       if modname.endswith('__init__'): 
        modname = modname[:-9] 
       if modname == '': 
        continue 
       yield import_module(modname) 


def get_testcases(module): 
    for name, value in getmembers(module): 
     if isclass(value) and issubclass(value, TestCase) and value is not TestCase: 
      print ' ', name, value 
      yield value 


def main(): 
    setup_test_environment() 

    testcases = set() 
    for module in get_modules(os.getcwd()): 
     for klass in get_testcases(module): 
      testcases.add(klass) 
    print 'found %d testcases' % (len(testcases),) 

    suite = TestSuite() 
    for case in testcases: 
     suite.addTest(TestLoader().loadTestsFromTestCase(case)) 

    print 'loaded %d tests' % (suite.countTestCases(),) 
    TextTestRunner(verbosity=2).run(suite) 


if __name__ == '__main__': 
    main() 
관련 문제