【发布时间】:2021-02-15 22:59:34
【问题描述】:
我正在尝试为我正在处理的 python 包生成代码覆盖率,并创建了一个 GitHub 操作来执行此操作,它使用 codecov-action。工作流程如下所示:
name: Code Coverage
on: [push]
jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.7
- name: Install dependencies
run: |
pip install pytest
pip install pytest-cov
pip install -r requirements.txt
- name: Generate coverage report
run: |
pytest --cov=./epispot --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
verbose: true
fail_ci_if_error: true
运行时会输出错误,可以查看here。 Pytest 输出错误代码 5 - 表示未找到任何测试 - 但是当我在计算机上运行它时,它可以正常工作。为什么会这样?
【问题讨论】:
-
默认情况下,您的文件必须命名为
*_test.py或test_*.py-- 我看到*-test.py-- 为什么它在本地工作超出了我的理解,也许您有一个本地配置文件不属于你的存储库? - 一个 pytest 核心开发 -
@AnthonySottile 测试文件在
tests/CI文件夹下都命名为test_*.py,我相信。 -
tests/CI的文件名格式正确,但文件中没有测试。你读过测试发现页面docs.pytest.org/en/stable/example/pythoncollection.html吗?
标签: github pytest code-coverage github-actions pytest-cov