Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce coverage requirement and reporting via codecov #672

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/tox-checkbox-ng.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-checkbox-support.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-provider-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-provider-certification-client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-provider-certification-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-provider-gpgpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-provider-iiotg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-provider-resource.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .github/workflows/tox-provider-sru.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
run: pip install tox
- name: Run tox
run: tox
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
40 changes: 37 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ you have to activate the `checkbox-cli service` on the Machine under test:
```bash
(venv) # checkbox-cli service
```
> Note: Keep in mind that service has to be run as root and needs the
> Note: Keep in mind that service has to be run as root and needs the
> virtual env, you may have to re-enable/activate it after a `sudo -s`

Now you can run the remote command to connect to it:
```bash
(venv) $ checkbox-cli remote IP
(venv) $ checkbox-cli remote IP
```

> Note: `service` and `remote` can both run on the same machine.
> Note: `service` and `remote` can both run on the same machine.
> in that situation, simply use `127.0.0.1`

### Writing and running unit tests for Checkbox
Expand All @@ -103,6 +103,40 @@ tests for providers:

$ ./manage.py test

### Coverage requirements

In Checkbox we have a coverage requirement for new PRs. This is to ensure
that if anyone has to edit the source in the future we have a reliable way
to determine if the edits are changing the meaning of it. Remember, it may be very
clear to you now, but what about tomorrow? Given this objective, try to
create your tests in a way that captures this spirit, it is not about having
a patch coverage of 80% or 81%. It is better to have a very clean and clear
test collection that covers a little bit less of your patch than a
monstrosity of mocks and patches that are just there to reach the coverage
quota.

To collect your coverage you can run the following:
```
$ python -m pip install coverage pytest pytest-cov
# cd to where your test is
$ python -m coverage run -m pytest .
```
Note that every part of this repository has a `.coveragerc` file, they should
already include anything you may want to see in the report. If something is
missing you can edit it but please, consult with the team before doing so.
Tests are intentionally excluded from the coverage report, this is because
test files tend to inflate the coverage with no real benefit, so don't
worry if you can not spot yours in the report.

Of course, you may only be interested in the coverage of your patch (for
example, if you change a file that has a very low coverage, we do not want
you to take up the challenge of testing it all if you don't want to!). The
easiest way to get this measurement is to open a new PR and connect it with
your branch. The `codecov.io` Bot should comment on it as soon as the `tox`
job relevant to your change is finished, giving you a handy report. Note
that the bot will tell you what you should improve to meet the requirements,
the constraints are listed in `codecov.yaml` in the repo root.

## Version control recommendations

### Commit title
Expand Down
1 change: 1 addition & 0 deletions checkbox-ng/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commands =
{envpython} {envsitepackagesdir}/plainbox/impl/providers/manifest/manage.py validate
{envpython} -m coverage run -m pytest
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
1 change: 1 addition & 0 deletions checkbox-support/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ commands =
{envpython} -m pip list
{envpython} -m coverage run -m pytest checkbox_support/
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
patch:
default:
target: 90%
1 change: 1 addition & 0 deletions providers/base/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ commands =
{envpython} manage.py validate
{envpython} -m coverage run manage.py test
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
1 change: 1 addition & 0 deletions providers/certification-client/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ commands =
{envpython} manage.py validate
{envpython} -m coverage run manage.py test
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
1 change: 1 addition & 0 deletions providers/certification-server/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ commands =
{envpython} manage.py validate
{envpython} -m coverage run manage.py test
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
1 change: 1 addition & 0 deletions providers/gpgpu/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ commands =
{envpython} manage.py validate
{envpython} -m coverage run manage.py test
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
1 change: 1 addition & 0 deletions providers/iiotg/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ commands =
{envpython} manage.py validate
{envpython} -m coverage run manage.py test
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
1 change: 1 addition & 0 deletions providers/resource/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commands =
{envpython} manage.py validate
{envpython} -m coverage run manage.py test
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
1 change: 1 addition & 0 deletions providers/sru/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ commands =
{envpython} manage.py validate
{envpython} -m coverage run manage.py test
{envpython} -m coverage report
{envpython} -m coverage xml

[testenv:py35]
deps =
Expand Down
Loading