Skip to content

Commit

Permalink
pytest: Collect code coverage in multiple workers too (OSGeo#4451)
Browse files Browse the repository at this point in the history
* pytest: Collect code coverage in multiple workers too

* utils: Handle paths that already have a .py extension in coverage_mapper

* CI: Set INITIAL_GISBASE and INITIAL_PWD env vars for running pytest with multiple workers

* Coverage: Omit gui/wxpython subfolders for now

They are not covered at all and take some noticeable time to collect

* Coverage: Remove unneeded omit patten for gui/wxpython subfolders
  • Loading branch information
echoix authored Oct 14, 2024
1 parent 761d98a commit 3a9059b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ omit =
${INITIAL_PWD-.}/.github/*
${INITIAL_PWD-.}/bin.*/*
${INITIAL_PWD-.}/dist.*/*
**/gui/wxpython/*/**
**/OBJ.*/*
source =
.
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,25 @@ jobs:
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
export LD_LIBRARY_PATH=$(grass --config path)/lib:$LD_LIBRARY_PATH
export INITIAL_GISBASE="$(grass --config path)"
export INITIAL_PWD="${PWD}"
pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
--numprocesses auto -ra . \
--numprocesses auto \
--cov \
--cov-context=test \
-ra . \
-m 'not needs_solo_run'
- name: Run pytest with a single worker (for tests marked with needs_solo_run)
run: |
export PYTHONPATH=`grass --config python_path`:$PYTHONPATH
export LD_LIBRARY_PATH=$(grass --config path)/lib:$LD_LIBRARY_PATH
export INITIAL_GISBASE="$(grass --config path)"
INITIAL_PWD="${PWD}" pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
export INITIAL_PWD="${PWD}"
pytest --verbose --color=yes --durations=0 --durations-min=0.5 \
--cov \
--cov-context=test \
--cov-append \
-ra . \
-m 'needs_solo_run'
- name: Fix non-standard installed script paths in coverage data
Expand Down
6 changes: 4 additions & 2 deletions utils/coverage_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ def map_scripts_paths(old_path):
if INITIAL_GISBASE is None or INITIAL_PWD is None:
return old_path
p = Path(old_path)
extension = ".py"
p_name = p.stem if p.suffix == extension else p.name
temporal_base = Path(INITIAL_GISBASE) / "scripts" / "t.*"
base = Path(INITIAL_GISBASE) / "scripts" / "*"
if p.match(str(temporal_base)):
return str(Path(INITIAL_PWD) / "temporal" / (p.name) / (p.name)) + ".py"
return str(Path(INITIAL_PWD) / "temporal" / (p_name) / (p_name)) + extension
if p.match(str(base)):
return str(Path(INITIAL_PWD) / "scripts" / (p.name) / (p.name)) + ".py"
return str(Path(INITIAL_PWD) / "scripts" / (p_name) / (p_name)) + extension

return old_path

Expand Down

0 comments on commit 3a9059b

Please sign in to comment.