diff options
author | Matt Clay <matt@mystile.com> | 2021-03-30 22:30:38 +0200 |
---|---|---|
committer | Matt Clay <matt@mystile.com> | 2021-03-30 23:30:15 +0200 |
commit | b75844af4579e9f96c7a19b5e9e18d0d7cbdb684 (patch) | |
tree | 10b962b2d7791c87694d23530aaa78341878d7e7 | |
parent | Fix comment in iptables unit test (#74061) (diff) | |
download | ansible-b75844af4579e9f96c7a19b5e9e18d0d7cbdb684.tar.xz ansible-b75844af4579e9f96c7a19b5e9e18d0d7cbdb684.zip |
Fix ansible-test coverage exporting.
ci_complete
ci_coverage
4 files changed, 17 insertions, 3 deletions
diff --git a/changelogs/fragments/ansible-test-fix-coverage-export.yml b/changelogs/fragments/ansible-test-fix-coverage-export.yml new file mode 100644 index 0000000000..6864e48dee --- /dev/null +++ b/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. diff --git a/test/lib/ansible_test/_internal/cli.py b/test/lib/ansible_test/_internal/cli.py index b585ecde49..7e2650c702 100644 --- a/test/lib/ansible_test/_internal/cli.py +++ b/test/lib/ansible_test/_internal/cli.py @@ -576,6 +576,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', @@ -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): """ diff --git a/test/lib/ansible_test/_internal/coverage/__init__.py b/test/lib/ansible_test/_internal/coverage/__init__.py index e8b9b3bfc5..183efa671c 100644 --- a/test/lib/ansible_test/_internal/coverage/__init__.py +++ b/test/lib/ansible_test/_internal/coverage/__init__.py @@ -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 diff --git a/test/lib/ansible_test/_internal/coverage/combine.py b/test/lib/ansible_test/_internal/coverage/combine.py index fa0b8f7d39..7f726267f6 100644 --- a/test/lib/ansible_test/_internal/coverage/combine.py +++ b/test/lib/ansible_test/_internal/coverage/combine.py @@ -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] = {} @@ -157,6 +160,9 @@ def _command_coverage_combine_powershell(args): 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] = {} |