Skip to content

Commit

Permalink
coverage: ensure that "coverage clean" does its job (#872)
Browse files Browse the repository at this point in the history
- removed parameters from "coverage run" as they should be read from
the .coveragerc file.
- moved the contents of .coveragerc file to tox.ini and removed the
.coveragerc file.
- "coverage clean" now can see "coverage run" is being executed in
parallel mode and can now clean the artifacts properly.
- tox:testenv:coverage now runs "coverage clean" after the coverage report
generation.
- "coverage" will now generate coverage data to tox temp directory instead
of the project root.

misc:
- moved all tool configs to the upper part of the tox.ini file.
- renamed "coverage" to "coveragereport" to better reflect the what the
environment does.

Supersedes #871

Signed-off-by: Mustafa Kemal Gilor <[email protected]>
  • Loading branch information
xmkg authored May 22, 2024
1 parent cc4d716 commit 5ee302a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
10 changes: 0 additions & 10 deletions .coveragerc

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r gh-test-requirements.txt
- name: Test with tox
run: tox -e py3
run: tox -e py3-coverage
- name: Test with tox (non-utc timezone)
run: tox -e py3-non-utc-tz
- name: Run pylint
Expand All @@ -40,8 +40,8 @@ jobs:
- name: Run pep8
run: tox -e pep8
if: matrix.python-version == '3.10'
- name: Run coverage
run: tox -e coverage
- name: Run coveragereport
run: tox -e coveragereport
if: matrix.python-version == '3.10'
- name: Run bashate
run: tox -e bashate
Expand Down
62 changes: 45 additions & 17 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
[tox]
skipsdist = True
envlist = py3,coverage,pep8,pylint,bashate,yamllint,functional,hotyvalidate
envlist = py3-coverage,coveragereport,pep8,pylint,bashate,yamllint,functional,hotyvalidate
sitepackages = False
minversion = 3.18.0

# Tool configuration
[flake8]
# H106: Don't put vim configuration in source files
# H203: Use assertIs(Not)None to check for None
# H204: Use assert(Not)Equal to check for equality
# H205: Use assert(Greater|Less)(Equal) for comparison
# H904: Delay string interpolations at logging calls
enable-extensions = H106,H203,H204,H205,H904
show-source = true
exclude = ./.*,build,dist,tests/unit/fake_data_root
import-order-style = pep8

[coverage:run]
parallel = True
branch = True
source = hotsos
omit = tests/*

[coverage:report]
ignore_errors = True
skip_empty = True
precision = 2
fail_under = 84

[testenv]
basepython = {env:TOX_PYTHON:python3}
unit_tests = {toxinidir}/tests/unit/
Expand All @@ -17,29 +41,27 @@ setenv =
PYTHONHASHSEED=0
TESTS_DIR={[testenv]unit_tests}
non-utc-tz: TZ=EST+5
PYTHON=coverage run --source hotsos --parallel-mode
# Override the default coverage output path to tox's temp directory
# so we don't pollute the root dir.
COVERAGE_FILE={temp_dir}/.coverage
# Override the default "PYTHON" when the "-coverage" is present.
# This allows us to run additional steps on top of the default
# test run, such as changing the default interpreter to "coverage run".
coverage: PYTHON=coverage run
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
coverage erase
coverage: coverage erase
# This environment can "optionally" gather coverage data with "-coverage"
# suffix. The gathered coverage data is consumed by the "coverage" environment
# which merges the data and then generates coverage reports in HTML and XML
# formats.
stestr run --random --slowest --test-path {[testenv]unit_tests} {posargs}

[testenv:pep8]
allowlist_externals = flake8
commands = flake8 -v --exclude=fake_data_root {posargs:{[testenv]pyfiles}}

[flake8]
# H106: Don't put vim configuration in source files
# H203: Use assertIs(Not)None to check for None
# H204: Use assert(Not)Equal to check for equality
# H205: Use assert(Greater|Less)(Equal) for comparison
# H904: Delay string interpolations at logging calls
enable-extensions = H106,H203,H204,H205,H904
show-source = true
exclude = ./.*,build,dist,tests/unit/fake_data_root
import-order-style = pep8

[testenv:pylint]
allowlist_externals = pylint
commands = pylint -v --rcfile={toxinidir}/pylintrc {posargs:{[testenv]pyfiles}}
Expand All @@ -59,13 +81,19 @@ commands = bash {toxinidir}/tools/test/functest.sh
[testenv:docs]
commands = sphinx-build -j auto -d {toxinidir}/doc/build/doctrees -b html {toxinidir}/doc/source doc/build/html

[testenv:coverage]
depends = py3
[testenv:coveragereport]
depends = py3-coverage
description =
'Generate code coverage reports from collected coverage information.
This environment depends on `py3-coverage` for generating the actual
code coverage data from the test run. To collect and generate in a
single step, run `tox -e py3-coverage,coveragereport`.'
commands =
coverage combine
coverage report
coverage html -d cover
coverage xml -o cover/coverage.xml
coverage erase

[testenv:hotyvalidate]
setenv = PYTHONPATH={toxinidir}
Expand Down

0 comments on commit 5ee302a

Please sign in to comment.