2016-09-16 3 views
5

내 현재 워크 플로는 tox test pytest와보고 범위를 코덱 라이 트로 트래비스 CI에서 테스트 한 github PR 및 빌드입니다.env 변수를 기반으로하는 Tox 실행 명령

travis.yml

[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 

그러나, 트래비스가 실패 내 범위보고를하게 풀 요청, 내 환경 변수를 전달하지 않는

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. 트래비스 문서는 솔루션이 보여

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' 

그러나 TOX 이것은 TOX 서브 프로세스 파이썬 모듈을 사용하고, 명령 (자연스럽게)와 같은 경우에는 인식하지 않기 때문에 동작하지 않는다.

TRAVIS_PULL_REQUEST 변수를 기반으로하는 pull 요청이 아닌 빌드에만 codeclimate-test-reporter를 실행하려면 어떻게해야합니까? 나 자신의 스크립트를 만들고 호출해야합니까? 더 똑똑한 솔루션이 있습니까?

+1

'tox.ini' 파일은 흐름 제어를 이해하지 못합니다 (이는 이해할 수있는 '.ini' 파일입니다). 논리를 사용하여 사용자 정의 스크립트를 만드는 것이 하나의 옵션입니다. 두 번째 옵션은 CI 관련 기능을'.travis.yml'로 옮기는 것입니다. 결국'tox.ini'에는 각 dev 로컬 시스템에서 실행될 수 있고 실행되어야하는 로직이 있어야합니다. ['pylint'] (https://github.com/PyCQA/pylint/blob/master/tox.ini)는 그런 일을합니다. 'coveralls' venv는 tox로 선언되지만'.travis.yml'에 항목에 의해 트리거됩니다. –

+1

나는 bash를 통해 제어 흐름을 만들 생각으로,'shell = True'를 하위 프로세스에 전달하려면 tox가 필요합니다. 그게 하드 코딩 된, 그리고 꽤 깊은 묻혀있다 : https://github.com/tox-dev/tox/blob/85cce631a1bab5fe056ed2cbbababebebc51b259/tox/session.py#L226 – RecursivelyIronic

+0

'/ bin/bash -c'와 같은 것이 작동 할 수 있습니까? – iScrE4m

답변

0

에서 내 솔루션은 모든 것을

Tox.ini

[testenv:py35] 
commands = 
    python setup.py testcov 
passenv = ... 
을 처리합니다 setup.py 명령을 통해려고하고 있다는 것을 호출 할 수 있습니다

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

tox.ini 파일을 가지고 travis.yml

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

+0

내 현재 솔루션 (https://github.com/iScrE4m/pyCardDeck/blob/master/setup.py#L34)은 솔직하게 유지하기가 어려울 것 같지만 여전히 마음에 들지 않습니다. – iScrE4m