mirror of
https://github.com/ansible/ansible.git
synced 2025-11-30 23:16:08 +07:00
ansible-test - Fix integration test code coverage (#86100)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
def test_coverage():
|
||||
pass
|
||||
A_CONSTANT = True
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
context/controller
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eu
|
||||
|
||||
python.py world.py
|
||||
@@ -0,0 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
print("Hello World!")
|
||||
@@ -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=(--venv --color --truncate 0 "${@}")
|
||||
|
||||
# run a lightweight test that generates code coverge output
|
||||
ansible-test sanity --test import "${common[@]}" --coverage
|
||||
# run a lightweight test that generates code coverage output
|
||||
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
|
||||
ansible-test coverage report "${common[@]}"
|
||||
ansible-test coverage report "${common[@]}" | tee coverage.report
|
||||
ansible-test coverage html "${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/*
|
||||
*/pytest
|
||||
*/AnsiballZ_*.py
|
||||
*/test/results/*
|
||||
*/test/results/.tmp/delegation/*
|
||||
"""
|
||||
|
||||
coverage_config = coverage_config.lstrip()
|
||||
@@ -279,8 +279,8 @@ def generate_collection_coverage_config() -> str:
|
||||
]
|
||||
|
||||
omit_patterns = [
|
||||
# {base}/ansible_collections/{ns}/{col}/tests/output/*
|
||||
os.path.join(data_context().content.root, data_context().content.results_path, '*'),
|
||||
# {base}/ansible_collections/{ns}/{col}/tests/output/.tmp/delegation/*
|
||||
os.path.join(data_context().content.root, data_context().content.results_path, '.tmp/delegation/*'),
|
||||
]
|
||||
|
||||
include = textwrap.indent('\n'.join(include_patterns), ' ' * 4)
|
||||
|
||||
Reference in New Issue
Block a user