【发布时间】:2019-10-31 00:09:58
【问题描述】:
我基于千篇一律的模板创建了一个全新的Python repository。一切看起来都很好,所以我现在尝试使用 travis 和 codecov 设置测试和测试覆盖率。我是 pytest 的新手,但我正在努力做正确的事情。在网上看了之后,我最终得到了这个设置:
在.travis.yml,我添加了以下内容:
install:
- pip install -U tox-travis
- pip install coverage
- pip install codecov
script:
- python setup.py install
- tox
- coverage run tests/test_foo.py
在我的tox.ini 文件中:
[testenv]
passenv = CI TRAVIS TRAVIS_*
setenv =
PYTHONPATH = {toxinidir}
PIPENV_IGNORE_VIRTUALENVS=1
deps =
pipenv
codecov
pytest
{py27}: pathlib2
commands_pre =
pipenv install --dev --skip-lock
codecov
我创建了一个最小的tests/test_foo.py 文件,其中包含以下内容(foo() 是包中当前存在的唯一函数)。
import pytest
import doctest
import neurokit2 as nk
if __name__ == '__main__':
doctest.testmod()
pytest.main()
def test_foo():
assert nk.foo() == 4
我有 travis 触发的 codecov 似乎没有通过测试。此外,在 travis 上,它说 Error: No coverage report found ????我想知道我做错了什么?
【问题讨论】:
-
我认为一个问题是
pytest没有完全定位您的测试文件;默认情况下,it needs to have the formtest_*.pyor*_test.py,如果我没记错的话。
标签: python unit-testing code-coverage pytest travis-ci