python-travis 中的工作服找不到覆盖范围
python-coveralls in travis does not find coverage
我正在尝试通过 travis-ci 使用 coveralls.io 设置一个小型 python 库。
库的当前结构是:
libconfig
├── .coverage
├── .coveragerc
├── .coveralls.yml
├── LICENSE
├── README.md
├── REQUIREMENTS
├── .gitignore
├── .travis.yml
├── libconfig
│ ├── __init__.py
│ ├── config.py
│ ├── evaluator.py
│ ├── tests
│ │ └── test_libconfig.py
│ └── util.py
├── package.json
├── setup.cfg
└── setup.py
我的 .coveragerc
看起来像这样:
[run]
branch = False
omit = */tests/*
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
if self\.debug
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
raise IOError
raise ValueError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
show_missing = True
ignore_errors = True
[html]
directory = coverage_html_report
当我在本地 运行 pytests 时,它确实提供了覆盖范围:
pytest --cov-config .coveragerc --cov=libconfig libconfig/tests
=========================== test session starts ============================
platform darwin -- Python 2.7.12, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /Users/bonet/SandBox/libconfig, inifile:
plugins: cov-2.5.1
collected 5 items
libconfig/tests/test_libconfig.py ..... [100%]
---------- coverage: platform darwin, python 2.7.12-final-0 ----------
Name Stmts Miss Cover Missing
------------------------------------------------------
libconfig/__init__.py 1 0 100%
libconfig/config.py 116 0 100%
libconfig/evaluator.py 20 0 100%
libconfig/util.py 34 0 100%
------------------------------------------------------
TOTAL 171 0 100%
========================= 5 passed in 1.56 seconds =========================
然后,我有我的.travis.yml
配置文件:
language: python
python:
- '2.7'
- '3.5'
- '3.6'
install:
- pip install -r REQUIREMENTS
- pip install coverage coveralls
- pip install python-coveralls
- pip install pytest pytest-cov
script:
- python setup.py install
- pytest --cov-config .coveragerc --cov=libconfig libconfig/tests
- coverage report --show-missing
after_success:
- coveralls
但是,当这个 运行s 在 travis-ci 中时,它没有给我任何报道:
The command "pytest --cov-config .coveragerc --cov=libconfig libconfig/tests" exited with 0.
$ coverage report --show-missing
Name Stmts Miss Cover Missing
------------------------------------------------------
libconfig/__init__.py 1 1 0% 8
libconfig/config.py 116 116 0% 13-404
libconfig/evaluator.py 20 20 0% 13-47
libconfig/util.py 34 34 0% 9-68
------------------------------------------------------
TOTAL 171 171 0%
The command "coverage report --show-missing" exited with 0.
我一直在四处寻找,但我还没有找到解决这个问题的方法,任何帮助都会非常感谢ci。
所以,这花了一段时间,但我确实找到了解决方案,可以在发起这个问题的 libconfig 回购中看到。
基本上,我现在运行 tox里面的命令,配置文件(tox.ini
)例如:
[tox]
envlist = py27, py35, py36
skip_missing_interpreters = true
[testenv]
changedir = libconfig/tests
commands =
python -c "import libconfig; print(libconfig.__version__)"
coverage erase
pytest --basetemp={envtmpdir} --cov-config {toxinidir}/.coveragerc --cov-report xml:/tmp/cov-single.xml --cov=libconfig
coverage report --show-missing
deps =
-rREQUIREMENTS
pytest
pytest-cov
coverage
coveralls
python-coveralls
确保创建 XML 覆盖率报告和 .travis.yml
看起来像:
language: python
sudo: false
branches:
only:
- master
- "/^v\d+\.\d+(\.\d+)?(-\S*)?$/"
matrix:
include:
- python: 2.7
env: TOXENV=py27
os: linux
- python: 3.5
env: TOXENV=py35
os: linux
- python: 3.6
env: TOXENV=py36
os: linux
after_success:
- pwd
- coveralls --data_file libconfig/tests/.coverage
- python-codacy-coverage -r /tmp/cov-single.xml
- bash <(curl -s https://codecov.io/bash) -Z -c -f /tmp/cov-single.xml
- python: 3.7-dev
env: TOXENV=py37
os: linux
- language: generic
env: TOXENV=py27
os: osx
- language: generic
env: TOXENV=py36
os: osx
before_install:
- bash ./ci/travis_before_install.sh
install:
- bash ./ci/travis_install.sh
script:
- tox
正确地将报告上传到服务器。
我正在尝试通过 travis-ci 使用 coveralls.io 设置一个小型 python 库。
库的当前结构是:
libconfig
├── .coverage
├── .coveragerc
├── .coveralls.yml
├── LICENSE
├── README.md
├── REQUIREMENTS
├── .gitignore
├── .travis.yml
├── libconfig
│ ├── __init__.py
│ ├── config.py
│ ├── evaluator.py
│ ├── tests
│ │ └── test_libconfig.py
│ └── util.py
├── package.json
├── setup.cfg
└── setup.py
我的 .coveragerc
看起来像这样:
[run]
branch = False
omit = */tests/*
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
if self\.debug
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
raise IOError
raise ValueError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
show_missing = True
ignore_errors = True
[html]
directory = coverage_html_report
当我在本地 运行 pytests 时,它确实提供了覆盖范围:
pytest --cov-config .coveragerc --cov=libconfig libconfig/tests
=========================== test session starts ============================
platform darwin -- Python 2.7.12, pytest-3.4.1, py-1.5.2, pluggy-0.6.0
rootdir: /Users/bonet/SandBox/libconfig, inifile:
plugins: cov-2.5.1
collected 5 items
libconfig/tests/test_libconfig.py ..... [100%]
---------- coverage: platform darwin, python 2.7.12-final-0 ----------
Name Stmts Miss Cover Missing
------------------------------------------------------
libconfig/__init__.py 1 0 100%
libconfig/config.py 116 0 100%
libconfig/evaluator.py 20 0 100%
libconfig/util.py 34 0 100%
------------------------------------------------------
TOTAL 171 0 100%
========================= 5 passed in 1.56 seconds =========================
然后,我有我的.travis.yml
配置文件:
language: python
python:
- '2.7'
- '3.5'
- '3.6'
install:
- pip install -r REQUIREMENTS
- pip install coverage coveralls
- pip install python-coveralls
- pip install pytest pytest-cov
script:
- python setup.py install
- pytest --cov-config .coveragerc --cov=libconfig libconfig/tests
- coverage report --show-missing
after_success:
- coveralls
但是,当这个 运行s 在 travis-ci 中时,它没有给我任何报道:
The command "pytest --cov-config .coveragerc --cov=libconfig libconfig/tests" exited with 0.
$ coverage report --show-missing
Name Stmts Miss Cover Missing
------------------------------------------------------
libconfig/__init__.py 1 1 0% 8
libconfig/config.py 116 116 0% 13-404
libconfig/evaluator.py 20 20 0% 13-47
libconfig/util.py 34 34 0% 9-68
------------------------------------------------------
TOTAL 171 171 0%
The command "coverage report --show-missing" exited with 0.
我一直在四处寻找,但我还没有找到解决这个问题的方法,任何帮助都会非常感谢ci。
所以,这花了一段时间,但我确实找到了解决方案,可以在发起这个问题的 libconfig 回购中看到。
基本上,我现在运行 tox里面的命令,配置文件(tox.ini
)例如:
[tox]
envlist = py27, py35, py36
skip_missing_interpreters = true
[testenv]
changedir = libconfig/tests
commands =
python -c "import libconfig; print(libconfig.__version__)"
coverage erase
pytest --basetemp={envtmpdir} --cov-config {toxinidir}/.coveragerc --cov-report xml:/tmp/cov-single.xml --cov=libconfig
coverage report --show-missing
deps =
-rREQUIREMENTS
pytest
pytest-cov
coverage
coveralls
python-coveralls
确保创建 XML 覆盖率报告和 .travis.yml
看起来像:
language: python
sudo: false
branches:
only:
- master
- "/^v\d+\.\d+(\.\d+)?(-\S*)?$/"
matrix:
include:
- python: 2.7
env: TOXENV=py27
os: linux
- python: 3.5
env: TOXENV=py35
os: linux
- python: 3.6
env: TOXENV=py36
os: linux
after_success:
- pwd
- coveralls --data_file libconfig/tests/.coverage
- python-codacy-coverage -r /tmp/cov-single.xml
- bash <(curl -s https://codecov.io/bash) -Z -c -f /tmp/cov-single.xml
- python: 3.7-dev
env: TOXENV=py37
os: linux
- language: generic
env: TOXENV=py27
os: osx
- language: generic
env: TOXENV=py36
os: osx
before_install:
- bash ./ci/travis_before_install.sh
install:
- bash ./ci/travis_install.sh
script:
- tox
正确地将报告上传到服务器。