diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index 6caf63b2c..000000000 --- a/.coveragerc +++ /dev/null @@ -1,10 +0,0 @@ -[run] -branch = True -source = hotsos -omit = tests/* - -[report] -ignore_errors = True -skip_empty = True -precision = 2 -fail_under = 84 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 769dbb48d..5047af475 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -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 @@ -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 diff --git a/tox.ini b/tox.ini index c20f4ffa1..719487ee9 100644 --- a/tox.ini +++ b/tox.ini @@ -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/ @@ -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}} @@ -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}