【问题标题】:Pytest not finding tests on GitHub actionsPytest 未在 GitHub 操作上找到测试
【发布时间】: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.pytest_*.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


【解决方案1】:

您可能不是这种情况,但是当我在分支中添加 Python 测试但将带有 pytest 的 Github 操作添加到 master 分支时,我遇到了这个问题。因此,pytest 没有找到任何测试,因为实际上没有。

在我将主分支与工作流合并到该分支中并进行测试后,使用 pytest 构建的 Python 已通过。

【讨论】:

    猜你喜欢
    • 2020-12-09
    • 2021-11-02
    • 2020-06-03
    • 2021-06-23
    • 2021-02-05
    • 2019-06-20
    • 1970-01-01
    • 2020-10-11
    • 2021-06-08
    相关资源
    最近更新 更多