]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/tox: adding coverage target to the main tox.ini 68570/head
authorRedouane Kachach <rkachach@ibm.com>
Thu, 23 Apr 2026 11:15:19 +0000 (13:15 +0200)
committerRedouane Kachach <rkachach@ibm.com>
Thu, 23 Apr 2026 12:09:10 +0000 (14:09 +0200)
Let's add a coverage target so we can measure this metric for mgr modules.

Usage examples:

Run coverage for a single module (percentages only):
  tox -e coverage -- cephadm
  tox -e coverage -- smb

Show uncovered line numbers:
  COVERAGE_REPORT=term-missing tox -e coverage -- cephadm

Generate a visual HTML report:
  COVERAGE_REPORT=html tox -e coverage -- cephadm
  firefox htmlcov/index.html

Signed-off-by: Redouane Kachach <rkachach@ibm.com>
src/pybind/mgr/tox.ini

index 94f7b8119a557d6a3a438ee6d27b800e92afd89e..46892ade74e647166bedf620b39a3e019a0f808c 100644 (file)
@@ -7,6 +7,7 @@ envlist =
     check-black
     check-isort
     py3
+    coverage
 skipsdist = true
 skip_missing_interpreters = true
 
@@ -45,6 +46,12 @@ addopts =
     --recursive \
     --ignore-local-config
 
+[coverage:report]
+omit =
+    */tests/*
+    */test_*.py
+    */templates/*
+
 [testenv]
 setenv =
     UNITTEST = true
@@ -66,6 +73,23 @@ commands =
     pytest {posargs:cephadm/tests/test_ssh.py}
 
 
+[testenv:coverage]
+setenv =
+    UNITTEST = true
+    PYTHONPATH = $PYTHONPATH:..
+deps =
+    {[base]deps}
+    pytest-cov
+# Default: percentages only
+# To show uncovered line numbers:
+#   COVERAGE_REPORT=term-missing tox -e coverage -- <module>
+# To generate a nice html with visual uncovered line numbers:
+#   COVERAGE_REPORT=html tox -e coverage -- <module>
+#   <your-browser> htmlcov/index.html
+commands =
+    pytest --cov={posargs:.} --cov-report={env:COVERAGE_REPORT:term} {posargs:.}
+
+
 [testenv:{,py37-,py38-,py39-,py310-}mypy]
 setenv =
     MYPYPATH = {toxinidir}/..:{toxinidir}/../../python-common