我已经创建了一个全新的Python存储库基于曲奇刀模板。一切看起来都很好,所以我现在试着用travis和codecov来设置测试和测试覆盖率。我是初出茅庐,但我正努力把事情做好。在互联网上查看之后,我得到了这样的设置:
在.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似乎没有通过测试。此外,关于特拉维斯,它说,Error: No coverage report found,我想知道我做错了什么?
发布于 2019-10-31 12:09:19
1)在项目目录中创建pytest.ini文件,并添加以下行
[pytest]
testpaths = tests
python_files = *.py
python_functions = test_*2)在项目目录中创建.coveragerc文件并添加以下行
[report]
fail_under = 90
show_missing = True3)代码覆盖的pytest
pytest --verbose --color=yes --cov=Name of directory for which you need code coverage --assert=plain注意:您需要代码覆盖的目录的名称必须在项目目录中。
发布于 2019-10-31 06:32:35
看起来你在你的安装上缺少了coverage。您可以在脚本中使用它,但它可能不会运行。尝试在您的pip install coverage文件中添加travis.yml。也试一试:codecov
https://stackoverflow.com/questions/58635279
复制相似问题