pytest-dev/pytest-cov

Package takes a while to run in GitHub workflow CI

nh916 opened this issue · 1 comments

nh916 commented

Description

We are using the pytest-cov within our project in our GitHub workflow to check that our tests cover at least 90% of our code, and I noticed that for some reason this workflow takes the longest to complete, and sometimes takes over an hour to finish. I am not sure if this is something I am doing wrong, the package is slow, or GitHub workflow is just slow. Our project does have over 150 tests as well, not sure if that is an issue or not. When running the package locally it is pretty fast. Please let me know your thoughts when possible, I am trying to optimize the GitHub workflow.

# use pytest-cov to see what percentage of the code is being covered by tests
# WARNING: this workflow will fail if any of the tests within it fail

name: Test Coverage

on:
  push:
    branches:
      - main
      - develop
  pull_request:
    branches:
      - main
      - develop

jobs:
  test-coverage:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        os: [ubuntu-latest]
        python-version: [3.11]

    steps:
      - uses: actions/checkout@v2

      - name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.11

      - name: upgrade pip
        run: pip install --upgrade pip

      - name: Install CRIPT Python SDK
        run: pip install -e .

      - name: Install requirements_dev.txt
        run: pip install -r requirements_dev.txt

      - name: Test Coverage
        run: pytest --cov --cov-fail-under=90

It just hangs in windows

name: "Python Release"
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
  release:
    types: [created]
jobs:
  unit-tests:
    strategy:
        matrix:
            os: [ubuntu-latest, windows-latest, macos-latest]
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.x"
      - name: Set up Node
        uses: actions/setup-node@v3
        with:
          node-version: 20
      - name: Install pypa/build
        run: >-
          python3 -m
          pip install
          build hatchling
          --user
      - name: Make VERSION
        run: python make_version.py
      - name: install self
        run: pip install -e .
      - name: Unit Tests
        run: pytest
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v3.1.1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
      - name: Style Guide
        run: flake8

If you let it run it times out, but force kill and you can see the tests completed in the same 10s it takes on Mac and Ubuntu.

For example run on open source project: https://github.com/StartupOS/verinfast/actions/runs/6263214547/job/17007095128