From 149a87895b4aec05c234073de2d8354e1d46f08e Mon Sep 17 00:00:00 2001 From: Axel Andersson <axel.andersson@volvocars.com> Date: Fri, 18 Oct 2024 09:00:47 +0200 Subject: [PATCH] Measure code coverage in tox tests Change-Id: Ib085b9b701c8d6e45fc0b5dd4205d473cd0642e6 --- NOTICE | 5 ++++- test-requirements.txt | 1 + tox.ini | 20 +++++++++++++++++++- zuul.d/tox.yaml | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/NOTICE b/NOTICE index 035bddf..b793f70 100644 --- a/NOTICE +++ b/NOTICE @@ -12,6 +12,7 @@ Notices Report Content Components: +Coverage 7.6.4: http://nedbatchelder.com/code/modules/coverage.html : Apache License 2.0 exceptiongroup 1.2.2: https://github.com/python-trio/exceptiongroup : MIT License flake8 7.1.1: https://gitlab.com/pycqa/flake8 : MIT License gitdb 4.0.11: http://github.com/gitpython-developers/gitdb : BSD 3-clause "New" or "Revised" License @@ -40,6 +41,8 @@ voluptuous 0.15.2: http://pypi.python.org/pypi/voluptuous : BSD 3-clause "New" o Copyright Text: +Coverage 7.6.4 pypi:coverage/7.6.4: http://nedbatchelder.com/code/modules/coverage.html + No Copyrights found exceptiongroup 1.2.2 pypi:exceptiongroup/1.2.2: https://github.com/python-trio/exceptiongroup Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -13368,7 +13371,7 @@ modification, are permitted provided that the following conditions are met: Licenses: Apache License 2.0 -(Packaging 24.1, pbr 6.1.0, powertrain-build 1.0.0, psf-requests 2.32.3) +(Coverage 7.6.4, Packaging 24.1, pbr 6.1.0, powertrain-build 1.0.0, psf-requests 2.32.3) Apache License Version 2.0, January 2004 diff --git a/test-requirements.txt b/test-requirements.txt index fbf5841..15d03e3 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,5 @@ pytest +coverage flake8 gitpython >= 3.1.8 ruamel.yaml == 0.17.21; python_version == "3.6" diff --git a/tox.ini b/tox.ini index 45bf356..3006869 100644 --- a/tox.ini +++ b/tox.ini @@ -23,4 +23,22 @@ deps = commands = flake8 powertrain_build tests [testenv:pytest] -commands = python -m pytest tests +commands = + coverage run -m pytest tests + coverage report + coverage html + +[coverage:run] +branch = True +source_pkgs = + powertrain_build + +[coverage:report] +skip_empty = true +omit = + */__main__.py +exclude_lines = + if __name__ == .__main__.: + +[coverage:html] +directory = cover diff --git a/zuul.d/tox.yaml b/zuul.d/tox.yaml index 7382df3..477e6fe 100644 --- a/zuul.d/tox.yaml +++ b/zuul.d/tox.yaml @@ -1,6 +1,6 @@ - job: name: powertrain-build-tox - parent: tox + parent: tox-cover vars: tox_envlist: flake8,pytest nodeset: ubuntu-jammy