Continuous Integration

https://d33wubrfki0l68.cloudfront.net/f1f854c5ebcb45734d7ec5a0a6e00d5803f430f2/ca191/_images/33907150594_9abba7ad0a_k_d.jpg

Note

For advice on writing your tests, see Testing Your Code.

Why?

Martin Fowler, who first wrote about Continuous Integration(short: CI) together with Kent Beck, describes CI as follows:

Continuous Integration is a software development practice where members ofa team integrate their work frequently, usually each person integrates atleast daily - leading to multiple integrations per day. Each integration isverified by an automated build (including test) to detect integration errorsas quickly as possible. Many teams find that this approach leads tosignificantly reduced integration problems and allows a team to developcohesive software more rapidly.

Jenkins

Jenkins CI is an extensible Continuous Integration engine. Use it.

Buildbot

Buildbot is a Python system toautomate the compile/test cycle to validate code changes.

Tox

tox is an automation tool providingpackaging, testing, and deployment of Python software right from the console orCI server. It is a generic virtualenv management and test command line toolwhich provides the following features:

  • Checking that packages install correctly with different Python versions andinterpreters
  • Running tests in each of the environments, configuring your test tool ofchoice
  • Acting as a front-end to Continuous Integration servers, reducing boilerplateand merging CI and shell-based testing

Travis-CI

Travis-CI is a distributed CI server which buildstests for open source projects for free. It provides multiple workers to runPython tests on and seamlessly integrates with GitHub. You can even have itcomment on your Pull Requests whether this particular changeset breaks thebuild or not. So if you are hosting your code on GitHub, Travis-CI is a greatand easy way to get started with Continuous Integration.

In order to get started, add a .travis.yml file to your repository withthis example content:

  1. language: python
  2. python:
  3. - "2.6"
  4. - "2.7"
  5. - "3.2"
  6. - "3.3"
  7. # command to install dependencies
  8. script: python tests/test_all_of_the_units.py
  9. branches:
  10. only:
  11. - master

This will get your project tested on all the listed Python versions byrunning the given script, and will only build the master branch. There are alot more options you can enable, like notifications, before and after steps,and much more. The Travis-CI docsexplain all of these options, and are very thorough.

In order to activate testing for your project, go to the Travis-CI siteand login with your GitHub account. Then activate your project in yourprofile settings and you’re ready to go. From now on, your project’s testswill be run on every push to GitHub.

原文: https://docs.python-guide.org/scenarios/ci/