Tox start command based on env variable

My current workflow is github PRs and Builds tested on Travis CI, with toxin testing and community coverage for coding.

travis.yml

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 

tox.ini

 [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 

However, Travis does not pass my environment variables for traction requests, which causes my coverage report to fail. The Travis documentation shows this as a solution:

 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' 

However, in the case of this toxin, this does not work, since the current uses the python subprocess module and does not recognize it as a command (naturally).

How to run codeclimate-test-reporter only for assemblies, not pull requests based on the TRAVIS_PULL_REQUEST variable? Should I create my own script and call? Is there a smarter solution?

+5
source share
2 answers

My solution goes through the setup.py command, which takes care of everything

Tox.ini

 [testenv:py35] commands = python setup.py testcov passenv = ... 

setup.py

 class PyTestCov(Command): description = "run tests and report them to codeclimate" user_options = [] def initialize_options(self): pass def finalize_options(self): pass def run(self): errno = call(["py.test --cov=pyCardDeck --durations=10 tests"], shell=True) if os.getenv("TRAVIS_PULL_REQUEST") == "false": call(["python -m codeclimate_test_reporter --file .coverage"], shell=True) raise SystemExit(errno) ... cmdclass={'testcov': PyTestCov}, 
0
source

You can have two tox.ini and a call from travis.yml

script: if [ $TRAVIS_PULL_REQUEST ]; then tox -c tox_nocodeclimate.ini; else tox -c tox.ini; fi

0
source

All Articles