Skip to content

Commit

Permalink
[stable-2.9] Fix ansible-test coverage exporting.
Browse files Browse the repository at this point in the history
(cherry picked from commit b75844a)
  • Loading branch information
mattclay committed Mar 31, 2021
1 parent 84e61b3 commit 7fa32b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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 @@ -505,6 +505,9 @@ def parse_args():
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 @@ -760,9 +763,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
8 changes: 8 additions & 0 deletions test/lib/ansible_test/_internal/cover.py
Expand Up @@ -138,6 +138,9 @@ def _command_coverage_combine_python(args):
if not filename:
continue

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 @@ -313,6 +316,8 @@ def _sanitise_filename(filename, modules=None, collection_search_re=None, collec
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 Expand Up @@ -510,6 +515,9 @@ def _default_stub_value(lines):
if not filename:
continue

if args.export:
filename = os.path.relpath(filename) # exported paths must be relative since absolute paths may differ between systems

if isinstance(hit_info, dict) and not hit_info.get('Line'):
# Input data was previously aggregated and thus uses the standard ansible-test output format for PowerShell coverage.
# This format differs from the more verbose format of raw coverage data from the remote Windows hosts.
Expand Down

0 comments on commit 7fa32b9

Please sign in to comment.