Conditional Commands in tox? (tox, travis-ci, and coveralls) Conditional Commands in tox? (tox, travis-ci, and coveralls) python python

Conditional Commands in tox? (tox, travis-ci, and coveralls)


An alternative solution would be to prefix the coveralls command with a dash (-) to tell tox to ignore its exit code as explained in the documentation. This way even failures from coveralls will be ignored and tox will consider the test execution as successful when executed locally.

Using the example configuration above, it would be as follows:

[tox]envlist = py27[testenv]passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCHdeps =    pytest    coverage    pytest-cov    coverallscommands =    py.test --cov={envsitepackagesdir}/mypackage --cov-report=term --basetemp={envtmpdir}    - coveralls


I have a similar setup with Travis, tox and coveralls. My idea was to only execute coveralls if the TRAVIS environment variable is set. However, it seems this is not so easy to do as tox has trouble parsing commands with quotes and ampersands. Additionally, this confused Travis me a lot.

Eventually I wrote a simple python script run_coveralls.py:

#!/bin/env/pythonimport osfrom subprocess import callif __name__ == '__main__':    if 'TRAVIS' in os.environ:        rc = call('coveralls')        raise SystemExit(rc)

In tox.ini, replace your coveralls command with python {toxinidir}/run_coveralls.py.


I am using a environmental variable to run additional commands.

tox.ini

commands =    coverage run runtests.py    {env:POST_COMMAND:python --version}

.travis.yml

language: pythonpython:  - "3.6"install: pip install tox-travisscript: toxenv:  - POST_COMMAND=codecov -e TOX_ENV

Now in my local setup, it print the python version. When run from Travis it runs codecov.