From 0b231644b754efba7a7851eb87c9e0ba747179fe Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 25 Aug 2020 10:48:52 -0700 Subject: [PATCH 1/3] Add integration test for ansible-test coverage. --- .../ansible-test/collection-tests/coverage.sh | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 test/integration/targets/ansible-test/collection-tests/coverage.sh diff --git a/test/integration/targets/ansible-test/collection-tests/coverage.sh b/test/integration/targets/ansible-test/collection-tests/coverage.sh new file mode 100755 index 00000000000000..3d01dd4bc1e768 --- /dev/null +++ b/test/integration/targets/ansible-test/collection-tests/coverage.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -eux -o pipefail + +cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}" +cd "${WORK_DIR}/ansible_collections/ns/col" + +# rename the sanity ignore file to match the current ansible version and update import ignores with the python version +ansible_version="$(python -c 'import ansible.release; print(".".join(ansible.release.__version__.split(".")[:2]))')" +sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" > "tests/sanity/ignore-${ansible_version}.txt" + +# common args for all tests +common=(--venv --color --truncate 0 "${@}") +test_common=("${common[@]}" --python "${ANSIBLE_TEST_PYTHON_VERSION}") + +# run a lightweight test that generates code coverge output +ansible-test sanity --test import "${test_common[@]}" --coverage + +# report on code coverage in all supported formats +ansible-test coverage report "${common[@]}" +ansible-test coverage html "${common[@]}" +ansible-test coverage xml "${common[@]}" From b838f50ca44b118bf45c283e471945d51669aa89 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 25 Aug 2020 10:55:54 -0700 Subject: [PATCH 2/3] Fix ansible-test coverage traceback. --- test/lib/ansible_test/_internal/cli.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lib/ansible_test/_internal/cli.py b/test/lib/ansible_test/_internal/cli.py index 23d4acfb273704..9fe35c9d3b410b 100644 --- a/test/lib/ansible_test/_internal/cli.py +++ b/test/lib/ansible_test/_internal/cli.py @@ -926,6 +926,7 @@ def add_environments(parser, isolated_delegation=True): remote_provider=None, remote_aws_region=None, remote_terminate=None, + remote_endpoint=None, python_interpreter=None, ) From 4aeac7b4835b1ec54b3e3f4c67f4f74832b558ef Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 25 Aug 2020 11:21:28 -0700 Subject: [PATCH 3/3] Fix coverage reporting on Python 2.6. --- changelogs/fragments/ansible-test-coverage-py26.yml | 2 ++ test/lib/ansible_test/_internal/coverage/__init__.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/ansible-test-coverage-py26.yml diff --git a/changelogs/fragments/ansible-test-coverage-py26.yml b/changelogs/fragments/ansible-test-coverage-py26.yml new file mode 100644 index 00000000000000..fb84b37c582d2a --- /dev/null +++ b/changelogs/fragments/ansible-test-coverage-py26.yml @@ -0,0 +1,2 @@ +minor_changes: + - ansible-test - Fix ``ansible-test coverage`` reporting sub-commands (``report``, ``html``, ``xml``) on Python 2.6. diff --git a/test/lib/ansible_test/_internal/coverage/__init__.py b/test/lib/ansible_test/_internal/coverage/__init__.py index 481eab8cd0e36c..88bb98431305c5 100644 --- a/test/lib/ansible_test/_internal/coverage/__init__.py +++ b/test/lib/ansible_test/_internal/coverage/__init__.py @@ -104,7 +104,7 @@ def run_coverage(args, output_file, command, cmd): # type: (CoverageConfig, str env = common_environment() env.update(dict(COVERAGE_FILE=output_file)) - cmd = ['python', '-m', 'coverage', command, '--rcfile', COVERAGE_CONFIG_PATH] + cmd + cmd = ['python', '-m', 'coverage.__main__', command, '--rcfile', COVERAGE_CONFIG_PATH] + cmd intercept_command(args, target_name='coverage', env=env, cmd=cmd, disable_coverage=True)