5

私の現在のワークフローは、Travis CI でテストされた github の PR とビルドであり、tox テスト pytest と codeclimate へのレポート カバレッジがあります。

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

しかし、Travis は私の環境変数をプル リクエストに渡さないため、カバレッジ レポートが失敗します。Travis のドキュメントでは、これを解決策として示しています。

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 が subprocess python モジュールを使用しており、(当然のことながら) コマンドとして認識されないため、これは機能しません。

TRAVIS_PULL_REQUEST 変数に基づくプル リクエストではなく、ビルドに対してのみ codeclimate-test-reporter を実行するにはどうすればよいですか? 独自のスクリプトを作成して呼び出す必要がありますか? よりスマートなソリューションはありますか?

4

2 に答える 2

1

あなたは2つのtox.iniファイルを持っていて、それを呼び出すことができますtravis.yml

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

于 2016-09-18T20:03:56.397 に答える
0

私の解決策は、すべてを処理する setup.py コマンドを使用することです

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},
于 2016-09-23T14:38:15.553 に答える