Skip to content

Commit 2de8ff2

Browse files
authored
Coverage testing (#2158)
* Add code coverage to test runs
1 parent c1d4b64 commit 2de8ff2

File tree

9 files changed

+96
-10
lines changed

9 files changed

+96
-10
lines changed

.github/workflows/save_coverage.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Upload coverage
2+
3+
on:
4+
workflow_run:
5+
workflows: ['Code Tests', 'Geopandas tests', 'Code Tests with Latest branca', 'Selenium Tests', 'Run Snapshot Tests', 'Run Streamlit Folium Tests']
6+
types: [completed]
7+
8+
jobs:
9+
run:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Download coverage files from previous steps
14+
id: download-artifacts
15+
uses: actions/download-artifact@v4
16+
with:
17+
path: combined-coverage
18+
pattern: coverage-*
19+
merge-multiple: true
20+
token: ${{ secrets.GITHUB_TOKEN }}
21+
22+
- name: Combine coverage
23+
run: coverage combine
24+
25+
- name: Generate report
26+
run: coverage html --skip-covered
27+
28+
- name: Upload coverage report
29+
if: always()
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: combined-coverage
33+
path: htmlcov/**
34+
fail-on-empty: false

.github/workflows/test_code.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ jobs:
4141
pip install pixelmatch
4242
4343
- name: Code tests
44-
run: python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots
44+
run: coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots
45+
46+
- name: Upload coverage
47+
if: always()
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: coverage-test-code
51+
path: |
52+
.coverage*

.github/workflows/test_geopandas.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,12 @@ jobs:
4646
- name: Run Geopandas tests
4747
run: |
4848
cd geopandas
49-
pytest -r a geopandas/tests/test_explore.py
49+
coverage run -p -m pytest -r a geopandas/tests/test_explore.py
50+
51+
- name: Upload coverage
52+
if: always()
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: coverage-test-geopandas
56+
path: |
57+
.coverage*

.github/workflows/test_latest_branca.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ jobs:
3333
run: |
3434
micromamba remove branca --yes --force
3535
python -m pip install git+https://github.com/python-visualization/branca.git
36-
python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots
36+
coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots
37+
38+
- name: Upload coverage
39+
if: always()
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: coverage-test-branca
43+
path: |
44+
.coverage*

.github/workflows/test_selenium.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ jobs:
3434

3535
- name: Selenium tests
3636
shell: bash -l {0}
37-
run: python -m pytest tests/selenium -vv
37+
run: coverage run -p -m pytest tests/selenium -vv
38+
39+
- name: Upload coverage
40+
if: always()
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: coverage-test-selenium
44+
path: |
45+
.coverage*

.github/workflows/test_snapshots.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Test with pytest
3737
shell: bash -l {0}
3838
run: |
39-
python -m pytest tests/snapshots -s --junit-xml=test-results.xml
39+
coverage run -p -m pytest tests/snapshots -s --junit-xml=test-results.xml
4040
4141
- name: Surface failing tests
4242
if: always()
@@ -53,3 +53,11 @@ jobs:
5353
path: |
5454
/tmp/screenshot_*_*.png
5555
/tmp/folium_map_*.html
56+
57+
- name: Upload coverage
58+
if: always()
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: coverage-test-snapshots
62+
path: |
63+
.coverage*

.github/workflows/test_streamlit_folium.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
playwright install --with-deps
5555
5656
- name: Install annotate-failures-plugin
57-
run: pip install pytest-github-actions-annotate-failures
57+
run: pip install pytest-github-actions-annotate-failures coverage
5858

5959
- name: Install folium from source
6060
shell: bash -l {0}
@@ -65,11 +65,20 @@ jobs:
6565
shell: bash -l {0}
6666
run: |
6767
cd streamlit_folium
68-
pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" --junit-xml=test-results.xml
68+
python -m pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update"
6969
7070
- name: Surface failing tests
7171
if: always()
7272
uses: pmeier/pytest-results-action@main
7373
with:
7474
path: streamlit_folium/test-results.xml
7575
fail-on-empty: false
76+
77+
78+
- name: Upload coverage
79+
if: always()
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: coverage-test-streamlit-folium
83+
path: |
84+
.coverage*

folium/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@
4646

4747
try:
4848
from ._version import __version__
49-
except ImportError:
49+
except ImportError: # pragma: no cover
5050
__version__ = "unknown"
5151

5252

5353
if branca.__version__ != "unknown" and tuple(
5454
int(x) for x in branca.__version__.split(".")[:2]
55-
) < (0, 3):
55+
) < (
56+
0,
57+
3,
58+
): # pragma: no cover
5659
raise ImportError(
5760
"branca version 0.3.0 or higher is required. "
5861
"Update branca with e.g. `pip install branca --upgrade`."

tests/snapshots/test_snapshots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_screenshot(path: str):
3535
m.save(f"/tmp/folium_map_{path}.html")
3636
assert mismatch < 200
3737

38-
else:
38+
else: # pragma: no cover
3939
shutil.copy(
4040
f"/tmp/screenshot_new_{path}.png",
4141
f"tests/snapshots/screenshots/screenshot_{path}.png",

0 commit comments

Comments
 (0)