diff --git a/.github/workflows/save_coverage.yml b/.github/workflows/save_coverage.yml new file mode 100644 index 0000000000..5e4641ec9c --- /dev/null +++ b/.github/workflows/save_coverage.yml @@ -0,0 +1,34 @@ +name: Upload coverage + +on: + workflow_run: + workflows: ['Code Tests', 'Geopandas tests', 'Code Tests with Latest branca', 'Selenium Tests', 'Run Snapshot Tests', 'Run Streamlit Folium Tests'] + types: [completed] + +jobs: + run: + runs-on: ubuntu-latest + + steps: + - name: Download coverage files from previous steps + id: download-artifacts + uses: actions/download-artifact@v4 + with: + path: combined-coverage + pattern: coverage-* + merge-multiple: true + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Combine coverage + run: coverage combine + + - name: Generate report + run: coverage html --skip-covered + + - name: Upload coverage report + if: always() + uses: actions/upload-artifact@v4 + with: + name: combined-coverage + path: htmlcov/** + fail-on-empty: false diff --git a/.github/workflows/test_code.yml b/.github/workflows/test_code.yml index e29dd68f20..ab966c9e29 100644 --- a/.github/workflows/test_code.yml +++ b/.github/workflows/test_code.yml @@ -41,4 +41,12 @@ jobs: pip install pixelmatch - name: Code tests - run: python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + run: coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-code + path: | + .coverage* diff --git a/.github/workflows/test_geopandas.yml b/.github/workflows/test_geopandas.yml index a7ed868b47..219b3db194 100644 --- a/.github/workflows/test_geopandas.yml +++ b/.github/workflows/test_geopandas.yml @@ -46,4 +46,12 @@ jobs: - name: Run Geopandas tests run: | cd geopandas - pytest -r a geopandas/tests/test_explore.py + coverage run -p -m pytest -r a geopandas/tests/test_explore.py + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-geopandas + path: | + .coverage* diff --git a/.github/workflows/test_latest_branca.yml b/.github/workflows/test_latest_branca.yml index c7ea3aaa19..0f0f4ea70e 100644 --- a/.github/workflows/test_latest_branca.yml +++ b/.github/workflows/test_latest_branca.yml @@ -33,4 +33,12 @@ jobs: run: | micromamba remove branca --yes --force python -m pip install git+https://github.com/python-visualization/branca.git - python -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + coverage run -p -m pytest -vv --ignore=tests/selenium --ignore=tests/playwright --ignore=tests/snapshots + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-branca + path: | + .coverage* diff --git a/.github/workflows/test_selenium.yml b/.github/workflows/test_selenium.yml index 61a87df02c..e1d876d33c 100644 --- a/.github/workflows/test_selenium.yml +++ b/.github/workflows/test_selenium.yml @@ -34,4 +34,12 @@ jobs: - name: Selenium tests shell: bash -l {0} - run: python -m pytest tests/selenium -vv + run: coverage run -p -m pytest tests/selenium -vv + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-selenium + path: | + .coverage* diff --git a/.github/workflows/test_snapshots.yml b/.github/workflows/test_snapshots.yml index 9555eff44e..14cac92028 100644 --- a/.github/workflows/test_snapshots.yml +++ b/.github/workflows/test_snapshots.yml @@ -36,7 +36,7 @@ jobs: - name: Test with pytest shell: bash -l {0} run: | - python -m pytest tests/snapshots -s --junit-xml=test-results.xml + coverage run -p -m pytest tests/snapshots -s --junit-xml=test-results.xml - name: Surface failing tests if: always() @@ -53,3 +53,11 @@ jobs: path: | /tmp/screenshot_*_*.png /tmp/folium_map_*.html + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-snapshots + path: | + .coverage* diff --git a/.github/workflows/test_streamlit_folium.yml b/.github/workflows/test_streamlit_folium.yml index d821a0c140..0ba8d449c8 100644 --- a/.github/workflows/test_streamlit_folium.yml +++ b/.github/workflows/test_streamlit_folium.yml @@ -55,7 +55,7 @@ jobs: playwright install --with-deps - name: Install annotate-failures-plugin - run: pip install pytest-github-actions-annotate-failures + run: pip install pytest-github-actions-annotate-failures coverage - name: Install folium from source shell: bash -l {0} @@ -66,7 +66,7 @@ jobs: shell: bash -l {0} run: | cd streamlit_folium - pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" --junit-xml=test-results.xml + python -m pytest tests/test_frontend.py --browser chromium -s --reruns 3 -k "not test_layer_control_dynamic_update" - name: Surface failing tests if: always() @@ -74,3 +74,12 @@ jobs: with: path: streamlit_folium/test-results.xml fail-on-empty: false + + + - name: Upload coverage + if: always() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-streamlit-folium + path: | + .coverage* diff --git a/folium/__init__.py b/folium/__init__.py index c6fa376e4c..67489f8c50 100644 --- a/folium/__init__.py +++ b/folium/__init__.py @@ -46,13 +46,16 @@ try: from ._version import __version__ -except ImportError: +except ImportError: # pragma: no cover __version__ = "unknown" if branca.__version__ != "unknown" and tuple( int(x) for x in branca.__version__.split(".")[:2] -) < (0, 3): +) < ( + 0, + 3, +): # pragma: no cover raise ImportError( "branca version 0.3.0 or higher is required. " "Update branca with e.g. `pip install branca --upgrade`." diff --git a/tests/snapshots/test_snapshots.py b/tests/snapshots/test_snapshots.py index 84c20211ba..8249bc1686 100644 --- a/tests/snapshots/test_snapshots.py +++ b/tests/snapshots/test_snapshots.py @@ -35,7 +35,7 @@ def test_screenshot(path: str): m.save(f"/tmp/folium_map_{path}.html") assert mismatch < 200 - else: + else: # pragma: no cover shutil.copy( f"/tmp/screenshot_new_{path}.png", f"tests/snapshots/screenshots/screenshot_{path}.png",