From d8930aca906b557ac225849f0fc20e408c8f85c3 Mon Sep 17 00:00:00 2001 From: Philip Loche Date: Thu, 21 Sep 2023 18:56:21 +0200 Subject: [PATCH] Add coverage for Python torch bindings --- .codecov.yml | 1 + .github/workflows/coverage.yml | 9 +++++++-- tox.ini | 6 ++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 3b8bba5e6..1a69398b1 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -13,3 +13,4 @@ fixes: # map coverage collected inside tox virtual environments # to the source dir in git - ".tox/all-deps/lib/*/site-packages/::python/" + - ".tox/torch-tests/lib/*/site-packages/::python/" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 6949a6c0d..d47130715 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -69,10 +69,15 @@ jobs: lcov --remove coverage.info '/usr/*' "$(pwd)/rascaline-c-api/tests/*" "$(pwd)/rascaline-c-api/examples/*" --output-file coverage.info - name: collect Python coverage - run: tox -e all-deps + run: | + tox -e all-deps + tox -e torch-tests + env: + # Use the CPU only version of torch when building/running the code + PIP_EXTRA_INDEX_URL: https://download.pytorch.org/whl/cpu - name: upload to codecov.io uses: codecov/codecov-action@v3 with: fail_ci_if_error: true - files: target/tarpaulin/cobertura.xml,.tox/coverage.xml,coverage.info + files: target/tarpaulin/cobertura.xml,.tox/coverage-all-deps.xml,.tox/coverage-torch-tests.xml,coverage.info diff --git a/tox.ini b/tox.ini index 9331a771e..c1397e7dd 100644 --- a/tox.ini +++ b/tox.ini @@ -25,6 +25,7 @@ metatensor-torch-requirement = metatensor-torch @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip\#subdirectory=python/metatensor-torch build-single-wheel = --no-deps --no-build-isolation --check-build-dependencies +test_option = --cov={env_site_packages_dir}/metatensor --cov-report xml:{tox_root}/.tox/coverage-{env_name}.xml --import-mode=append commands = # error if the user gives a wrong testenv name in `tox -e` @@ -55,7 +56,7 @@ deps = pytest-cov commands = - pytest --cov={env_site_packages_dir}/rascaline --cov-report xml:.tox/coverage.xml --import-mode=append {posargs} + pytest {[testenv]test_option} {posargs} [testenv:min-deps] @@ -73,6 +74,7 @@ deps = {[testenv]metatensor-torch-requirement} pytest + pytest-cov numpy torch ase @@ -85,7 +87,7 @@ commands = # install rascaline-torch pip install . {[testenv]build-single-wheel} --force-reinstall # run the unit tests - pytest --import-mode=append --assert=plain {posargs} + pytest {[testenv]test_option} --assert=plain {posargs} [testenv:docs] deps =