2014-02-26 109 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