2014-02-26 160 views
7

我有幾個Django項目,我使用Jenkins進行持續集成。我已經完成了這個安排並運行了一段時間,並且運行良好。使用django-jenkins進行覆蓋測試

我希望能夠生成自動測試覆蓋率報告並讓Jenkins處理它們。它看起來像django-jenkins是這樣的方式,所以我安裝它和coverage

這裏是我的settings.py相關章節:

# Jenkins integration 
INSTALLED_APPS += ('django_jenkins',) 
JENKINS_TASKS = ( 
    'django_jenkins.tasks.with_coverage', 
    'django_jenkins.tasks.run_pylint', 
    'django_jenkins.tasks.django_tests', 
) 
PROJECT_APPS = ['myapp'] 

現在,我可以運行python manage.py jtest,它按預期工作。但是,如果我跑python manage.py jenkins,它的錯誤:

Traceback (most recent call last): 
    File "manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
    File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line 
    utility.execute() 
    File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command 
    klass = load_command_class(app_name, subcommand) 
    File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 76, in load_command_class 
    return module.Command() 
    File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django_jenkins/management/commands/__init__.py", line 61, in __init__ 
    for module_name in self.get_task_list()] 
    File "/home/matthew/Projects/blah/venv/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module 
    __import__(name) 
ImportError: No module named django_tests 

我使用的是標準的Django TestCaseLiveServerTestCase類作爲我的測試的基礎。任何想法,我哪裏錯了?該文檔似乎暗示django_tests已被刪除,但我無法找到任何跡象表明您現在如何運行Django測試。

我正在使用Django 1.6.2。

回答

11

剛剛意識到我已經有點數了。所有我需要做的是放下django_tests線,像這樣:

# Jenkins integration 
INSTALLED_APPS += ('django_jenkins',) 
JENKINS_TASKS = ( 
    'django_jenkins.tasks.with_coverage', 
    'django_jenkins.tasks.run_pylint', 
) 
PROJECT_APPS = ['myapp'] 

而且django-jenkins將運行測試,而不必明確要求它這樣做。

5

有一個在django_jenkins(0.18.0)最新版本的變化,使得django_jenkins.tasks.with_coverage詹金斯任務也不再需要。

相反,執行試運行,如下所示:

python manage.py jenkins --enable-coverage 

python3 manage.py jenkins --enable-coverage 

你可以找到更多關於該項目的GitHub Repo