简体   繁体   中英

Can I use travis-ci to test against specific (including minor number) version of python?

If you have this in your .travis.yml file:

language: python
python:
- 2.7

Your code will be tested against python 2.7.9:

$ source ~/virtualenv/python2.7/bin/activate
$ python --version
Python 2.7.9

But Python 2.7.9 breaks urllib3 ( https://github.com/shazow/urllib3/issues/482 ) and gevent ( https://github.com/gevent/gevent/issues/477 ). I guess this is why the latest Ubuntu still ships with Python 2.7.6.

For these reasons I really need to test my library against python >=2.7 but <2.7.9, is it possible to somehow specify minor python version in .travis.yml ? I've tried:

python:
- 2.7.6

but it doesn't work. Any ideas?

As far as I know you cannot specify minor versions with Travis. But what you could do instead is using Anaconda with the conda environment. Thereby, you can install a local version of python of your choice.

In your before_install script you can download and set it up via:

  - wget http://repo.continuum.io/miniconda/Miniconda-3.7.3-Linux-x86_64.sh -O miniconda.sh
  - bash miniconda.sh -b -p $HOME/miniconda
  - export PATH="$HOME/miniconda/bin:$PATH"
  - conda config --set always_yes yes --set changeps1 no
  - conda update -q conda
  # Useful for debugging any issues with conda
  - conda info -a
  # USE YOUR PYTHON VERSION HERE
  - conda create -q -n py276 python=2.7.6 
  - source activate py276

The important part here is, of course: conda create -q -n py276 python=2.7.6 .

Thus, calls to python in your Travis script will automatically use the one installed with anaconda, ie Python 2.7.6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM