Skip to content

Commit

Permalink
Add coverage test
Browse files Browse the repository at this point in the history
  • Loading branch information
boxydog committed Jun 8, 2024
1 parent 8c7c29e commit a00c37c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
82 changes: 73 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ jobs:

strategy:
matrix:
os: [ubuntu, macos, windows]
python: ["3.10", "3.11", "3.12"]
include:
- os: ubuntu
python: "3.8"
- os: ubuntu
python: "3.9"
# TODO: implement windows
# os: [ubuntu, macos, windows]
os: [ubuntu]
# TODO: put back 3.11, 3.12
# python: ["3.10", "3.11", "3.12"]
python: ["3.10"]
# TODO: put back 3.8, 3.9
# include:
# - os: ubuntu
# python: "3.8"
# - os: ubuntu
# python: "3.9"

steps:
- uses: actions/checkout@v4
Expand All @@ -39,14 +44,47 @@ jobs:
pandoc-version: "2.9.2"
- name: Install tox
run: python -m pip install -U pip tox
- name: Set up dependencies with invoke
if: runner.os != 'Windows'
run: |
# our tasks.py wants a virtualenv
python -m venv .venv
source .venv/bin/activate
echo $VIRTUAL_ENV
which python
python -m pip install invoke
python -m invoke setup
- name: Info
run: |
echo "===== PYTHON ====="
python --version
echo "===== PANDOC ====="
pandoc --version | head -2
- name: Run tests
run: tox -e py${{ matrix.python }}
- name: Run tests with coverage
if: runner.os != 'Windows'
run: |
source .venv/bin/activate
python -m coverage run pytest_all.py
ls -l .coverage.*
env:
# control the filename to avoid issues with uploading
# see also https://github.com/actions/upload-artifact/issues/478#issuecomment-2096976037
COVERAGE_FILE: .coverage.${{ matrix.os }}.${{ matrix.python }}.${{ github.event_name }}

- name: Upload coverage data
uses: "actions/upload-artifact@v4"
with:
name: coverage-data
path: ".coverage.${{ matrix.os }}.${{ matrix.python }}.${{ github.event_name }}"
if-no-files-found: error

# see https://github.com/actions/upload-artifact/blob/main/merge/README.md#combining-all-artifacts-in-a-workflow-run
merge:
runs-on: ubuntu-latest
needs: upload
steps:
- name: Merge Artifacts
uses: actions/upload-artifact/merge@v4

lint:
name: Lint
Expand All @@ -66,6 +104,32 @@ jobs:
- name: Run pre-commit checks on all files
uses: pre-commit/[email protected]

coverage:
runs-on: "ubuntu-latest"
needs: merge
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: "pip"
cache-dependency-path: "**/requirements/*"

- name: "Install Coverage.py"
run: "python -m pip install --upgrade coverage[toml]"

- name: "Download coverage data"
uses: actions/download-artifact@v4
with:
name: coverage-data

- name: "Combine & check coverage"
run: |
set -xe
python -m coverage combine
python -m coverage report --fail-under=74
build:
name: Test build
runs-on: ubuntu-latest
Expand Down
10 changes: 10 additions & 0 deletions pytest_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""
Discover and run all tests in the current directory and subdirectories.
This is useful to run coverage on tests across environments.
"""

import pytest

if __name__ == "__main__":
pytest.main()

0 comments on commit a00c37c

Please sign in to comment.