Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ansible-test coverage traceback. #71446

Merged
merged 3 commits into from Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to Python 2.6? Or do you mean 3.6?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests uncovered a bug running the coverage reporting commands on Python 2.6. Since that bug exists in released versions of ansible-test I added a changelog fragment for the fix which is included in this PR. I didn't add a changelog fragment for the coverage traceback since it hasn't gone into any release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, makes sense :)

22 changes: 22 additions & 0 deletions 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[@]}"
1 change: 1 addition & 0 deletions test/lib/ansible_test/_internal/cli.py
Expand Up @@ -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,
)

Expand Down
2 changes: 1 addition & 1 deletion test/lib/ansible_test/_internal/coverage/__init__.py
Expand Up @@ -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)

Expand Down