diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 75bc448..16e814f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -54,7 +54,30 @@ jobs: run: python -m pip install -e ".[dev]" - name: Run tests - run: python -m pytest tests/ -v + run: python -m pytest tests/ -v --cov --cov-report=term --cov-report=json + + # Coverage badge: the percentage is written to a gist that shields.io + # renders in README. Only from main and from a single matrix entry so + # PRs and duplicate uploads never overwrite the number. + - name: Read coverage percentage + if: github.ref == 'refs/heads/main' && matrix.python-version == '3.12' + id: coverage + run: | + percent=$(python -c 'import json; print(round(json.load(open("coverage.json"))["totals"]["percent_covered"]))') + echo "percent=$percent" >> "$GITHUB_OUTPUT" + + - name: Update coverage badge + if: github.ref == 'refs/heads/main' && matrix.python-version == '3.12' + uses: schneegans/dynamic-badges-action@v1.9.0 + with: + auth: ${{ secrets.GIST_SECRET }} + gistID: 77b084ed0d46c740183f89ec66af8a95 + filename: python-sdk-coverage.json + label: coverage + message: ${{ steps.coverage.outputs.percent }}% + valColorRange: ${{ steps.coverage.outputs.percent }} + minColorRange: 50 + maxColorRange: 90 - name: Verify package builds run: | diff --git a/.gitignore b/.gitignore index 16ded3f..8cef4a6 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,8 @@ ENV/ # Testing .pytest_cache/ .coverage +coverage.json +coverage.xml htmlcov/ # Type checkers diff --git a/pyproject.toml b/pyproject.toml index cc3bfd3..cb344f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,6 +48,7 @@ dev = [ "ruff>=0.6", "mypy>=1.10", "types-requests>=2.28", + "pytest-cov>=4", ] [project.urls] @@ -67,6 +68,13 @@ captcha_solver_api = ["py.typed"] [tool.pytest.ini_options] asyncio_mode = "auto" +[tool.coverage.run] +source = ["captcha_solver_api"] +branch = true + +[tool.coverage.report] +show_missing = true + [tool.mypy] # mypy 2.x cannot target 3.9; 3.10 is the lowest it accepts. Runtime # compatibility with 3.9 is still covered by the CI test matrix.