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 exporting. #74077

Merged
merged 1 commit into from Mar 30, 2021
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
6 changes: 6 additions & 0 deletions changelogs/fragments/ansible-test-fix-coverage-export.yml
@@ -0,0 +1,6 @@
bugfixes:
- ansible-test - The ``--export`` option for ``ansible-test coverage`` is now limited to the ``combine`` command.
It was previously available for reporting commands on which it had no effect.
- ansible-test - The ``ansible-test coverage combine`` option ``--export`` now exports relative paths.
This avoids loss of coverage data when aggregating across systems with different absolute paths.
Paths will be converted back to absolute when generating reports.
6 changes: 3 additions & 3 deletions test/lib/ansible_test/_internal/cli.py
Expand Up @@ -576,6 +576,9 @@ def key_value_type(value): # type: (str) -> t.Tuple[str, str]
coverage_combine.set_defaults(func=command_coverage_combine,
config=CoverageConfig)

coverage_combine.add_argument('--export',
help='directory to export combined coverage files to')

add_extra_coverage_options(coverage_combine)

coverage_erase = coverage_subparsers.add_parser('erase',
Expand Down Expand Up @@ -986,9 +989,6 @@ def add_extra_coverage_options(parser):
action='store_true',
help='generate empty report of all python/powershell source files')

parser.add_argument('--export',
help='directory to export combined coverage files to')


def add_httptester_options(parser, argparse):
"""
Expand Down
2 changes: 2 additions & 0 deletions test/lib/ansible_test/_internal/coverage/__init__.py
Expand Up @@ -288,6 +288,8 @@ def sanitize_filename(
display.info('%s -> %s' % (filename, new_name), verbosity=3)
filename = new_name

filename = os.path.abspath(filename) # make sure path is absolute (will be relative if previously exported)

return filename


Expand Down
6 changes: 6 additions & 0 deletions test/lib/ansible_test/_internal/coverage/combine.py
Expand Up @@ -79,6 +79,9 @@ def _command_coverage_combine_python(args):
continue

for filename, arcs in enumerate_python_arcs(coverage_file, coverage, modules, collection_search_re, collection_sub_re):
if args.export:
filename = os.path.relpath(filename) # exported paths must be relative since absolute paths may differ between systems

if group not in groups:
groups[group] = {}

Expand Down Expand Up @@ -157,6 +160,9 @@ def _default_stub_value(lines):
continue

for filename, hits in enumerate_powershell_lines(coverage_file, collection_search_re, collection_sub_re):
if args.export:
filename = os.path.relpath(filename) # exported paths must be relative since absolute paths may differ between systems

if group not in groups:
groups[group] = {}

Expand Down