Tox running command based on env variable
<p>My current workflow is github PRs and Builds tested on Travis CI, with tox testing pytest and reporting coverage to codeclimate. </p>

<p><strong>travis.yml</strong></p>

<pre><code>os:
- linux
sudo: false
language: python
python:
- "3.3"
- "3.4"
- "3.5"
- "pypy3"
- "pypy3.3-5.2-alpha1"
- "nightly"
install: pip install tox-travis
script: tox
</code></pre>

<p><strong>tox.ini</strong></p>

<pre><code>[tox]
envlist = py33, py34, py35, pypy3, docs, flake8, nightly, pypy3.3-5.2-alpha1

[tox:travis]
3.5 = py35, docs, flake8

[testenv]
deps = -rrequirements.txt
platform =
    win: windows
    linux: linux
commands =
    py.test --cov=pyCardDeck --durations=10 tests

[testenv:py35]
commands =
    py.test --cov=pyCardDeck --durations=10 tests
    codeclimate-test-reporter --file .coverage
passenv =
    CODECLIMATE_REPO_TOKEN
    TRAVIS_BRANCH
    TRAVIS_JOB_ID
    TRAVIS_PULL_REQUEST
    CI_NAME
</code></pre>

<p>However, Travis isn't passing my environmental variables for pull requests, which makes my coverage reporting fail. Travis documentation shows this as solution: </p>

<pre><code>script:
   - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./travis/run_on_pull_requests; fi'
   - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./travis/run_on_non_pull_requests; fi'
</code></pre>

<p>However, in tox this doesn't work as tox is using subprocess python module and doesn't recognize if as a command (naturally). </p>

<p>How do I run codeclimate-test-reporter only for builds and not for pull requests based on the TRAVIS_PULL_REQUEST variable? Do I have to create my own script and call that? Is there a smarter solution?</p>

<p>You can have two <code>tox.ini</code> files and call that from <code>travis.yml</code></p>

<p><code>script: if [ $TRAVIS_PULL_REQUEST ]; then tox -c tox_nocodeclimate.ini; else tox -c tox.ini; fi</code></p>

python travis-ci tox code-climate