ansible-test - Fix integration test code coverage (#86100)

pull/86101/head
Matt Clay 1 month ago committed by GitHub
parent f2a4d6de12
commit 13496b9e11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- ansible-test - Restore code coverage reporting for Python code residing in integration tests.

@ -1,5 +1,4 @@
from __future__ import annotations from __future__ import annotations
def test_coverage(): A_CONSTANT = True
pass

@ -0,0 +1,5 @@
from __future__ import annotations
def test_me() -> None:
pass

@ -7,10 +7,31 @@ set -x
# common args for all tests # common args for all tests
common=(--venv --color --truncate 0 "${@}") common=(--venv --color --truncate 0 "${@}")
# run a lightweight test that generates code coverge output # run a lightweight test that generates code coverage output
ansible-test sanity --test import "${common[@]}" --coverage ansible-test sanity --test import "${common[@]}" --coverage --python "${ANSIBLE_TEST_PYTHON_VERSION}"
# run an integration test that generates code coverage for a Python file within the integration test
ansible-test integration "${common[@]}" --coverage
# run a unit test that generates code coverage using a venv
ansible-test units "${common[@]}" --coverage --python "${ANSIBLE_TEST_PYTHON_VERSION}" --venv
# report on code coverage in all supported formats # report on code coverage in all supported formats
ansible-test coverage report "${common[@]}" ansible-test coverage report "${common[@]}" | tee coverage.report
ansible-test coverage html "${common[@]}" ansible-test coverage html "${common[@]}"
ansible-test coverage xml "${common[@]}" ansible-test coverage xml "${common[@]}"
# ensure import test coverage was collected
grep '^plugins/module_utils/test_util.py .* 100%$' coverage.report
# ensure integration test coverage was collected
grep '^tests/integration/targets/hello/world.py .* 100%$' coverage.report
# ensure unit test coverage was collected
grep '^tests/unit/test_something.py .* 100%$' coverage.report
# ensure tests/output/ (from --venv) does not appear in the coverage report (except in the report filename)
if grep "^tests/output/" coverage.report; then
echo "unexpected coverage output: tests/output/"
exit 1
fi

@ -261,7 +261,7 @@ omit =
*/pyshared/* */pyshared/*
*/pytest */pytest
*/AnsiballZ_*.py */AnsiballZ_*.py
*/test/results/* */test/results/.tmp/delegation/*
""" """
coverage_config = coverage_config.lstrip() coverage_config = coverage_config.lstrip()
@ -279,8 +279,8 @@ def generate_collection_coverage_config() -> str:
] ]
omit_patterns = [ omit_patterns = [
# {base}/ansible_collections/{ns}/{col}/tests/output/* # {base}/ansible_collections/{ns}/{col}/tests/output/.tmp/delegation/*
os.path.join(data_context().content.root, data_context().content.results_path, '*'), os.path.join(data_context().content.root, data_context().content.results_path, '.tmp/delegation/*'),
] ]
include = textwrap.indent('\n'.join(include_patterns), ' ' * 4) include = textwrap.indent('\n'.join(include_patterns), ' ' * 4)

Loading…
Cancel
Save