Skip to content

Commit

Permalink
Fix code coverage generation for sonar (#297)
Browse files Browse the repository at this point in the history
It seems almost impossible to get sonar to understand the coverage report
if it is not generated using the "source" installation.
So we re-run unit tests after a `python3 setup.py develop` in order to generate
a "correct" report.

Signed-off-by: Sylvain Leclerc <[email protected]>
  • Loading branch information
sylvlecl authored Jan 27, 2022
1 parent eeca5c5 commit 010cdac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[run]
command_line=-m unittest discover --start-directory tests
branch = True
include = */pypowsybl/*
13 changes: 10 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ jobs:
run: pip3 install wheelhouse/*.whl --user

- name: Run tests
working-directory: ./tests
working-directory: ./tests # Run in subdir to use installed lib, not sources
run: |
pytest
- name: Generate coverage # In order to generate a coverage that sonar understands, we need to generate it from sources
if: matrix.python.name == 'cp39'
run: |
coverage run -m pytest
pip3 uninstall -y pypowsybl
python3 setup.py develop
coverage run -m pytest tests/
coverage xml
- name: Sonar analysis
Expand All @@ -82,7 +89,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: |
-Dsonar.python.coverage.reportPaths=tests/coverage.xml
-Dsonar.python.coverage.reportPaths=coverage.xml
- name: Run doc examples
working-directory: ./docs
Expand Down
2 changes: 1 addition & 1 deletion cpp/lib/pybind11
Submodule pybind11 updated 189 files
3 changes: 3 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ sonar.projectKey=powsybl_pypowsybl
# in https://sonarcloud.io/documentation/project-administration/narrowing-the-focus/
sonar.sources=pypowsybl
sonar.tests=tests

# to get specific analysis for those versions
sonar.python.version=3.7,3.8,3.9,3.10

0 comments on commit 010cdac

Please sign in to comment.