From 817f62e5b1b0d05ba49d0968ed261adc23da775c Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Wed, 16 Aug 2023 17:06:18 +0000 Subject: [PATCH 1/3] refactor: install and run coverage directly python 3.11 so coverage can use pyproject.toml config --- pyproject.toml | 8 ++++++-- tests/run.sh | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 39b9a2e..7301a2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ keywords = ["gam", "google"] authors = [ { name = "Compiler LLC", email = "dev@compiler.la" } ] -requires-python = ">=3.9" +requires-python = ">=3.11" dependencies = [ "advanced-gam-for-google-workspace @ git+https://github.com/taers232c/GAMADV-XTD3.git@v6.61.14#subdirectory=src" ] @@ -26,8 +26,8 @@ dev = [ "pre-commit" ] test = [ + "coverage", "pytest", - "pytest-cov", "pytest-mock" ] @@ -43,6 +43,10 @@ line-length = 127 target-version = ['py311'] include = '\.pyi?$' +[tool.coverage.run] +branch = true +source = ["compiler_admin"] + [tool.pyright] include = ["compiler_admin", "tests"] diff --git a/tests/run.sh b/tests/run.sh index 7f4bab8..2bd0554 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -2,7 +2,7 @@ set -eu # run normal pytests, skip e2e tests -pytest -m "not e2e" --cov=compiler_admin --cov-branch --import-mode=importlib +coverage run -m pytest -m "not e2e" # clean out old coverage results rm -rf ./tests/coverage From c2361d522ab7d8aaa2921df1fa7246b7965e5533 Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Wed, 16 Aug 2023 17:10:40 +0000 Subject: [PATCH 2/3] feat(ci): diff coverage report also creates coverage badge --- .github/workflows/pytest.yml | 23 +++++++++++++++++------ pyproject.toml | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index c339fae..48837d7 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,12 +1,22 @@ name: Pytest on: - - push - - pull_request + pull_request: + push: + branches: + - "main" jobs: pytest: runs-on: ubuntu-latest + permissions: + # Gives the action the necessary permissions for publishing new + # comments in pull requests. + pull-requests: write + # Gives the action the necessary permissions for pushing data to the + # python-coverage-comment-action branch, and for editing existing + # comments (to avoid publishing multiple comments in the same PR) + contents: write steps: - name: Check out code uses: actions/checkout@v3 @@ -28,8 +38,9 @@ jobs: - name: Run tests run: ./tests/run.sh - - name: Upload coverage report - uses: actions/upload-artifact@v3 + - name: Coverage comment + uses: py-cov-action/python-coverage-comment-action@v3 with: - name: coverage-report - path: ./tests/coverage + GITHUB_TOKEN: ${{ github.token }} + MINIMUM_GREEN: 90 + MINIMUM_ORANGE: 80 diff --git a/pyproject.toml b/pyproject.toml index 7301a2c..0dfe0ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ include = '\.pyi?$' [tool.coverage.run] branch = true +relative_files = true source = ["compiler_admin"] [tool.pyright] From bfafb9cd89027e74d52965185d4a4bab45979f1b Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Wed, 16 Aug 2023 17:11:22 +0000 Subject: [PATCH 3/3] chore(tests): helper to view local coverage report --- tests/web.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 tests/web.sh diff --git a/tests/web.sh b/tests/web.sh new file mode 100755 index 0000000..09d5854 --- /dev/null +++ b/tests/web.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eu + +python -m http.server -d ./tests/coverage