Skip to content

Commit

Permalink
Improve coverage report
Browse files Browse the repository at this point in the history
First enable coverage for child processes, so we get coverage report
from the drenv tool and from script run by the drenv tool. This is a bit
tricky, requiring enabling coverage for child process using a .pth file
and using coverage parallel mode, combining output from multiple
processes.

With this change we report now all code running during the tests:

    $ make coverage
    python3 -m coverage report
    Name                  Stmts   Miss  Cover
    -----------------------------------------
    drenv/__init__.py        77     48    38%
    drenv/__main__.py       109     23    79%
    drenv/clusteradm.py      41     41     0%
    drenv/commands.py        93      2    98%
    drenv/envfile.py         80      0   100%
    drenv/kubectl.py         31      0   100%
    -----------------------------------------
    TOTAL                   431    114    74%

Part-of: #677
Signed-off-by: Nir Soffer <[email protected]>
  • Loading branch information
nirs committed Jan 9, 2023
1 parent 4962921 commit 546a166
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ jobs:
- name: Install tools
run: pip install -r test/requirements.txt

- name: Enable coverage for child processes
run: cp test/coverage.pth $(python -m site --user-site)

- name: Install drenv
run: pip install -e test

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ config/hub/bundle
test/drenv.egg-info/
test/**/__pycache__/
test/.coverage
test/.coverage.*
test/.vimrc
4 changes: 4 additions & 0 deletions test/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
parallel = True
source = drenv
omit = drenv/*_test.py
4 changes: 3 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ black-reformat:
python3 -m black drenv */start */test

test:
python3 -m coverage run --source drenv -m pytest
rm -f .coverage.*
COVERAGE_PROCESS_START=.coveragerc python3 -m coverage run -m pytest
python3 -m coverage combine --quiet

coverage:
python3 -m coverage report
Expand Down
9 changes: 9 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ This is a configuration for testing regional DR using a hub cluster and
pip install -r requirements.txt
```

### Enabling full test coverage

To enable test coverage for child processes, copy the `coverage.pth`
file to the python installation:

```
cp coverage.pth ~/.venv/ramen/lib/python*/site-packages
```

### Running the tests

Run all linters and tests and report test coverage:
Expand Down
1 change: 1 addition & 0 deletions test/coverage.pth
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import coverage; coverage.process_startup()

0 comments on commit 546a166

Please sign in to comment.