Skip to content

Commit

Permalink
chore: fix coverage
Browse files Browse the repository at this point in the history
For some reason, the `pytest-cov` plugin undercounts coverage (specifically: not counting top-level statements), while the `coverage` command itself gives correct results.
  • Loading branch information
kalekundert committed Dec 20, 2022
1 parent 4dcb634 commit df94f35
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 71 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release
on: workflow_dispatch

jobs:
release:
name: Release to PyPI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
# Make sure the whole repository history is present, so that
# python-semantic-release can decide if a new release is needed.
fetch-depth: 0

- uses: relekang/python-semantic-release@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Test and release

on:
push:
branches: ['master']
pull_request:
branches: ['master']

jobs:
test:
name: Run tests
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install test dependencies
run: |
pip install --upgrade pip
pip install -e .[test] coverage[toml]
- name: Run test suite
run: |
# The `pytest-cov` plugin somehow prevents all of the module-level
# statements in this package from being counted as covered. I have
# no idea how; maybe because I use pytest within the package itself?
# Whatever the reason, I get the correct coverage info when I run
# `coverage` directly.
coverage run -m pytest
coverage xml
- name: Report test coverage
uses: codecov/codecov-action@v3
62 changes: 0 additions & 62 deletions .github/workflows/test_and_release.yml

This file was deleted.

6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Temporary file hierarchies for pytest
:alt: Documentation
:target: https://pytest_tmp_files.readthedocs.io/en/latest/?badge=latest

.. image:: https://img.shields.io/github/actions/workflow/status/kalekundert/pytest_tmp_files/test_and_release.yml?branch=master
.. image:: https://img.shields.io/github/actions/workflow/status/kalekundert/pytest_tmp_files/test.yml?branch=master
:alt: Test status
:target: https://github.com/kalekundert/pytest_tmp_files/actions

.. image:: https://img.shields.io/coveralls/kalekundert/pytest_tmp_files.svg
.. image:: https://img.shields.io/codecov/c/gh/kalekundert/pytest_tmp_files.svg
:alt: Test coverage
:target: https://coveralls.io/github/kalekundert/pytest_tmp_files?branch=master
:target: https://app.codecov.io/gh/kalekundert/pytest_tmp_files

.. image:: https://img.shields.io/github/last-commit/kalekundert/pytest_tmp_files?logo=github
:alt: Last commit
Expand Down
13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ dependencies = [
[project.optional-dependencies]
test = [
'pytest',
'pytest-cov',
'coveralls',
'openpyxl',
]
doc = [
'sphinx',
Expand All @@ -44,6 +43,16 @@ tmp_files = 'pytest_tmp_files.plugin'
addopts = "--doctest-modules --doctest-glob='*.rst'"
doctest_optionflags = 'NORMALIZE_WHITESPACE'

[tool.coverage.run]
branch = true
source = ['pytest_tmp_files']

[tool.coverage.report]
exclude_lines = [
"^\\s*raise AssertionError\\b",
"^\\s*raise NotImplementedError\\b",
]

[tool.pccc]
header_length = 72
types = ["chore", "docs", "feat", "fix", "refactor", "style", "test"]
Expand Down
4 changes: 0 additions & 4 deletions tests/.coveragerc

This file was deleted.

0 comments on commit df94f35

Please sign in to comment.