我有一些我工作的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 TestCase
和LiveServerTestCase
类作为测试的基础。知道我哪里错了吗?文档似乎暗示django_tests
已被删除,但我找不到任何关于你现在如何运行Django测试的指示。
我正在使用Django 1.6.2。
答案 0 :(得分: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
将运行测试,而不必明确要求它这样做。
答案 1 :(得分:5)
最新版本的django_jenkins(0.18.0)发生了变化,因此不再需要 django_jenkins.tasks.with_coverage Jenkins任务。
而是按如下方式执行测试运行:
python manage.py jenkins --enable-coverage
或
python3 manage.py jenkins --enable-coverage
您可以在项目GitHub Repo上找到更多信息。