我目前的工作流程是在Travis CI上测试github PR和Builds,使用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正在使用子进程python模块,并且不会识别是否作为命令(自然地)。
如何仅针对构建运行codeclimate-test-reporter而不针对基于TRAVIS_PULL_REQUEST变量的pull请求运行?我是否必须创建自己的脚本并调用它?有更聪明的解决方案吗?
答案 0 :(得分:1)
您可以拥有两个child_added
个文件,并从tox.ini
travis.yml
答案 1 :(得分: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},