Browse code

Fix ansible-test coverage exporting.

ci_complete
ci_coverage

Matt Clay authored on 2021/03/31 05:30:38
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,6 @@
0
+bugfixes:
1
+  - ansible-test - The ``--export`` option for ``ansible-test coverage`` is now limited to the ``combine`` command.
2
+                   It was previously available for reporting commands on which it had no effect.
3
+  - ansible-test - The ``ansible-test coverage combine`` option ``--export`` now exports relative paths.
4
+                   This avoids loss of coverage data when aggregating across systems with different absolute paths.
5
+                   Paths will be converted back to absolute when generating reports.
... ...
@@ -576,6 +576,9 @@ def parse_args():
576 576
     coverage_combine.set_defaults(func=command_coverage_combine,
577 577
                                   config=CoverageConfig)
578 578
 
579
+    coverage_combine.add_argument('--export',
580
+                                  help='directory to export combined coverage files to')
581
+
579 582
     add_extra_coverage_options(coverage_combine)
580 583
 
581 584
     coverage_erase = coverage_subparsers.add_parser('erase',
... ...
@@ -986,9 +989,6 @@ def add_extra_coverage_options(parser):
986 986
                         action='store_true',
987 987
                         help='generate empty report of all python/powershell source files')
988 988
 
989
-    parser.add_argument('--export',
990
-                        help='directory to export combined coverage files to')
991
-
992 989
 
993 990
 def add_httptester_options(parser, argparse):
994 991
     """
... ...
@@ -288,6 +288,8 @@ def sanitize_filename(
288 288
         display.info('%s -> %s' % (filename, new_name), verbosity=3)
289 289
         filename = new_name
290 290
 
291
+    filename = os.path.abspath(filename)  # make sure path is absolute (will be relative if previously exported)
292
+
291 293
     return filename
292 294
 
293 295
 
... ...
@@ -79,6 +79,9 @@ def _command_coverage_combine_python(args):
79 79
             continue
80 80
 
81 81
         for filename, arcs in enumerate_python_arcs(coverage_file, coverage, modules, collection_search_re, collection_sub_re):
82
+            if args.export:
83
+                filename = os.path.relpath(filename)  # exported paths must be relative since absolute paths may differ between systems
84
+
82 85
             if group not in groups:
83 86
                 groups[group] = {}
84 87
 
... ...
@@ -157,6 +160,9 @@ def _command_coverage_combine_powershell(args):
157 157
             continue
158 158
 
159 159
         for filename, hits in enumerate_powershell_lines(coverage_file, collection_search_re, collection_sub_re):
160
+            if args.export:
161
+                filename = os.path.relpath(filename)  # exported paths must be relative since absolute paths may differ between systems
162
+
160 163
             if group not in groups:
161 164
                 groups[group] = {}
162 165