2014-10-29 66 views

回答

0

我結束了做以下 -

#!/usr/bin/env python 

from app import test_settings 
from django.core.management import call_command 
import django 
import os 
import sys 

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.test_settings') 
django.setup() 

# We only suppose 'unit' and 'integration' tests 
test_type = sys.argv[1] if len(sys.argv) == 2 else 'unit' 
for app_name in test_settings.CUSTOM_APPS: 
    try: 
     module = '{}.tests.{}'.format(app_name, test_type) 
     __import__(module) 
     print('Module \'{}\' exists. Running {} tests...' 
       .format(module, test_type)) 
     call_command('test', module, verbosity=2, failfast=True, pattern='*.py') 
    except ImportError: 
     print('Module \'{}\' doesn\'t exist. Checking next...'.format(module)) 
3

使用glob模塊

import glob 
print glob.glob("tests/unit/*.py") 

,那麼你可以手動從那裏傳文件....但林不知道這其實是你在找什麼...

這樣的事情

run_tests.py

import glob 
files = glob.glob("*/tests/unit/*.py") 
os.system("admin.py runtests "+" ".join(files)) 
+0

我基本上正在尋找使用Django的manage.py test'命令指定我是否要運行基於目錄結構我上面顯示單元測試或集成測試。請注意,我的項目中有應用程序,這就是爲什麼我想指定文件夾級別通配符而不是'--filter'開關使用的文件級通配符。 – 2014-10-30 11:28:22

+0

查看我的更新回答 – 2014-10-30 16:09:54

+0

比我發佈的答案要容易得多!好想法。 – 2014-10-30 16:10:28

相關問題