From 6bbe4147e50b8e520d63e8e894ba16dfbfbd4edc Mon Sep 17 00:00:00 2001
From: Christoph Alt <typ@ohnebild.com>
Date: Fri, 15 Sep 2023 10:48:23 +0200
Subject: [PATCH] added coverage testing

---
 .gitignore     |  4 +++-
 .gitlab-ci.yml |  7 +++++++
 pyproject.toml | 18 ++++++++++++++++--
 tox.ini        |  4 +++-
 4 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore
index 0d682a3..299ebbf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,6 @@ __pycache__/
 *.egg-info/
 .env
 .tox
-report.xml
+*.xml
+.coverage
+
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 188e39c..3e99d55 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -11,6 +11,13 @@ test:
    script:
       - pip install tox
       - tox -e py38
+   artifacts:
+     reports:
+       coverage_report:
+         coverage_format: cobertura
+         path: coverage.xml
+       junit:
+         - report.xml
 
 deploy_uniformgrid_gpu:
   stage: deploy
diff --git a/pyproject.toml b/pyproject.toml
index 3f1c32f..6ec0cc3 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -5,7 +5,7 @@ description="Collection of scripts and wrapper of contious benchmarking"
 readme = "README.md"
 requires-python = ">=3.8"
 authors = [
-    { name = "Christoph Alt", email="christoph.alt@fau.de" }
+{ name = "Christoph Alt", email="christoph.alt@fau.de" }
 ]
 license = { file = "LICENSE" }
 
@@ -26,10 +26,24 @@ plotting = [
 dashboard = [
     "grafanalib",
 ]
-test = ["pytest"]
+test = [
+    "coverage",
+    "pytest",
+    "pytest-cov"
+]
 
 [project.scripts]
 get_frequency = "cbutil.cpu_frequency:main"
 
 [tools.setuptools]
 packages = ["cbutil", "cbutil.postprocessing", "dashboards", "plotting"]
+
+[tool.coverage.run]
+branch = true
+source = ["cbutil", "dashboards", "plotting"]
+exclude_lines = [
+    "if __name__ == __main__",
+]
+
+[tool.coverage.html]
+directory = "coverage_html_report"
diff --git a/tox.ini b/tox.ini
index 711b6c8..db9c694 100644
--- a/tox.ini
+++ b/tox.ini
@@ -3,4 +3,6 @@ envlist = py38, py310, py311
 
 [testenv]
 extras = dashboard, plotting, test
-commands = pytest --junitxml=report.xml
+commands =
+    pytest --junitxml=report.xml
+    pytest --cov --cov-report html --cov-report term --cov-report xml
-- 
GitLab