* [stable-2.10] Fix ansible-test coverage traceback. (#71446)
* Add integration test for ansible-test coverage.
* Fix ansible-test coverage traceback.
* Fix coverage reporting on Python 2.6.
(cherry picked from commit f5b6df14ab2e691f5f059fff0fcf59449132549f)
Co-authored-by: Matt Clay <mclay@redhat.com>
* Add empty ignore.txt file for tests.
1 | 3 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,22 @@ |
0 |
+#!/usr/bin/env bash |
|
1 |
+ |
|
2 |
+set -eux -o pipefail |
|
3 |
+ |
|
4 |
+cp -a "${TEST_DIR}/ansible_collections" "${WORK_DIR}" |
|
5 |
+cd "${WORK_DIR}/ansible_collections/ns/col" |
|
6 |
+ |
|
7 |
+# rename the sanity ignore file to match the current ansible version and update import ignores with the python version |
|
8 |
+ansible_version="$(python -c 'import ansible.release; print(".".join(ansible.release.__version__.split(".")[:2]))')" |
|
9 |
+sed "s/ import$/ import-${ANSIBLE_TEST_PYTHON_VERSION}/;" < "tests/sanity/ignore.txt" > "tests/sanity/ignore-${ansible_version}.txt" |
|
10 |
+ |
|
11 |
+# common args for all tests |
|
12 |
+common=(--venv --color --truncate 0 "${@}") |
|
13 |
+test_common=("${common[@]}" --python "${ANSIBLE_TEST_PYTHON_VERSION}") |
|
14 |
+ |
|
15 |
+# run a lightweight test that generates code coverge output |
|
16 |
+ansible-test sanity --test import "${test_common[@]}" --coverage |
|
17 |
+ |
|
18 |
+# report on code coverage in all supported formats |
|
19 |
+ansible-test coverage report "${common[@]}" |
|
20 |
+ansible-test coverage html "${common[@]}" |
|
21 |
+ansible-test coverage xml "${common[@]}" |
... | ... |
@@ -104,7 +104,7 @@ def run_coverage(args, output_file, command, cmd): # type: (CoverageConfig, str |
104 | 104 |
env = common_environment() |
105 | 105 |
env.update(dict(COVERAGE_FILE=output_file)) |
106 | 106 |
|
107 |
- cmd = ['python', '-m', 'coverage', command, '--rcfile', COVERAGE_CONFIG_PATH] + cmd |
|
107 |
+ cmd = ['python', '-m', 'coverage.__main__', command, '--rcfile', COVERAGE_CONFIG_PATH] + cmd |
|
108 | 108 |
|
109 | 109 |
intercept_command(args, target_name='coverage', env=env, cmd=cmd, disable_coverage=True) |
110 | 110 |
|