我目前的工作流程是github PRs,并在Travis CI上进行了测试,并进行了毒性测试,并报告了对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: toxtox.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并没有将我的环境变量传递给pull请求,这使得我的报道失败了。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测试报告,而不是针对基于TRAVIS_PULL_REQUEST变量的拉请求运行?我必须创建自己的脚本并称之为吗?有更聪明的解决方案吗?
发布于 2016-09-23 14:38:15
我的解决方案是通过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-18 20:03:56
您可以有两个tox.ini文件并从travis.yml调用
script: if [ $TRAVIS_PULL_REQUEST ]; then tox -c tox_nocodeclimate.ini; else tox -c tox.ini; fi
https://stackoverflow.com/questions/39530802
复制相似问题