@@ -405,7 +405,9 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
405
405
# Always combine and generate the XML coverage report
406
406
try :
407
407
session .run (
408
- "coverage" , "combine" , "--debug=pathmap" , env = coverage_base_env
408
+ "coverage" ,
409
+ "combine" ,
410
+ env = coverage_base_env ,
409
411
)
410
412
except CommandFailed :
411
413
# Sometimes some of the coverage files are corrupt which would trigger a CommandFailed
@@ -417,7 +419,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
417
419
"xml" ,
418
420
"-o" ,
419
421
str (COVERAGE_OUTPUT_DIR .joinpath ("tests.xml" ).relative_to (REPO_ROOT )),
420
- "--omit=salt/*,artifacts/salt/* " ,
422
+ "--omit=salt/*" ,
421
423
"--include=tests/*,pkg/tests/*" ,
422
424
env = coverage_base_env ,
423
425
)
@@ -428,7 +430,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
428
430
"-o" ,
429
431
str (COVERAGE_OUTPUT_DIR .joinpath ("salt.xml" ).relative_to (REPO_ROOT )),
430
432
"--omit=tests/*,pkg/tests/*" ,
431
- "--include=salt/*,artifacts/salt/* " ,
433
+ "--include=salt/*" ,
432
434
env = coverage_base_env ,
433
435
)
434
436
# Generate html report for tests code coverage
@@ -437,7 +439,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
437
439
"html" ,
438
440
"-d" ,
439
441
str (COVERAGE_OUTPUT_DIR .joinpath ("html" ).relative_to (REPO_ROOT )),
440
- "--omit=salt/*,artifacts/salt/* " ,
442
+ "--omit=salt/*" ,
441
443
"--include=tests/*,pkg/tests/*" ,
442
444
env = coverage_base_env ,
443
445
)
@@ -448,7 +450,7 @@ def _run_with_coverage(session, *test_cmd, env=None, on_rerun=False):
448
450
"-d" ,
449
451
str (COVERAGE_OUTPUT_DIR .joinpath ("html" ).relative_to (REPO_ROOT )),
450
452
"--omit=tests/*,pkg/tests/*" ,
451
- "--include=salt/*,artifacts/salt/* " ,
453
+ "--include=salt/*" ,
452
454
env = coverage_base_env ,
453
455
)
454
456
@@ -499,36 +501,37 @@ def _report_coverage(session):
499
501
)
500
502
cmd_args = [
501
503
"--omit=tests/*,pkg/tests/*" ,
502
- "--include=salt/*,artifacts/salt/* " ,
504
+ "--include=salt/*" ,
503
505
]
504
506
505
507
elif report_section == "tests" :
506
508
json_coverage_file = (
507
509
COVERAGE_OUTPUT_DIR .relative_to (REPO_ROOT ) / "coverage-tests.json"
508
510
)
509
511
cmd_args = [
510
- "--omit=salt/*,artifacts/salt/* " ,
512
+ "--omit=salt/*" ,
511
513
"--include=tests/*,pkg/tests/*" ,
512
514
]
513
515
else :
514
516
json_coverage_file = (
515
517
COVERAGE_OUTPUT_DIR .relative_to (REPO_ROOT ) / "coverage.json"
516
518
)
517
519
cmd_args = [
518
- "--include=salt/*,artifacts/salt/*, tests/*,pkg/tests/*" ,
520
+ "--include=salt/*,tests/*,pkg/tests/*" ,
519
521
]
520
522
521
523
session .run (
522
524
"coverage" ,
523
- "json" ,
524
- "-o" ,
525
- str (json_coverage_file ),
525
+ "report" ,
526
526
* cmd_args ,
527
527
env = env ,
528
528
)
529
+
529
530
session .run (
530
531
"coverage" ,
531
- "report" ,
532
+ "json" ,
533
+ "-o" ,
534
+ str (json_coverage_file ),
532
535
* cmd_args ,
533
536
env = env ,
534
537
)
@@ -1379,14 +1382,71 @@ def create_html_coverage_report(session):
1379
1382
"COVERAGE_FILE" : str (COVERAGE_FILE ),
1380
1383
}
1381
1384
1385
+ report_section = None
1386
+ if session .posargs :
1387
+ report_section = session .posargs .pop (0 )
1388
+ if report_section not in ("salt" , "tests" ):
1389
+ session .error ("The report section can only be one of 'salt', 'tests'." )
1390
+ if session .posargs :
1391
+ session .error (
1392
+ "Only one argument can be passed to the session, which is optional "
1393
+ "and is one of 'salt', 'tests'."
1394
+ )
1395
+
1396
+ if not IS_WINDOWS :
1397
+ # The coverage file might have come from a windows machine, fix paths
1398
+ with sqlite3 .connect (COVERAGE_FILE ) as db :
1399
+ res = db .execute (r"SELECT * FROM file WHERE path LIKE '%salt\%'" )
1400
+ if res .fetchone ():
1401
+ session_warn (
1402
+ session ,
1403
+ "Replacing backwards slashes with forward slashes on file "
1404
+ "paths in the coverage database" ,
1405
+ )
1406
+ db .execute (r"UPDATE OR IGNORE file SET path=replace(path, '\', '/');" )
1407
+
1408
+ if report_section == "salt" :
1409
+ report_dir = str (
1410
+ COVERAGE_OUTPUT_DIR .joinpath ("html" , "salt" ).relative_to (REPO_ROOT )
1411
+ )
1412
+ json_coverage_file = (
1413
+ COVERAGE_OUTPUT_DIR .relative_to (REPO_ROOT ) / "coverage-salt.json"
1414
+ )
1415
+ cmd_args = [
1416
+ "--omit=tests/*,pkg/tests/*" ,
1417
+ "--include=salt/*" ,
1418
+ ]
1419
+
1420
+ elif report_section == "tests" :
1421
+ report_dir = str (
1422
+ COVERAGE_OUTPUT_DIR .joinpath ("html" , "tests" ).relative_to (REPO_ROOT )
1423
+ )
1424
+ json_coverage_file = (
1425
+ COVERAGE_OUTPUT_DIR .relative_to (REPO_ROOT ) / "coverage-tests.json"
1426
+ )
1427
+ cmd_args = [
1428
+ "--omit=salt/*" ,
1429
+ "--include=tests/*,pkg/tests/*" ,
1430
+ ]
1431
+ else :
1432
+ report_dir = str (
1433
+ COVERAGE_OUTPUT_DIR .joinpath ("html" , "full" ).relative_to (REPO_ROOT )
1434
+ )
1435
+ json_coverage_file = (
1436
+ COVERAGE_OUTPUT_DIR .relative_to (REPO_ROOT ) / "coverage.json"
1437
+ )
1438
+ cmd_args = [
1439
+ "--include=salt/*,tests/*,pkg/tests/*" ,
1440
+ ]
1441
+
1382
1442
# Generate html report for Salt and tests combined code coverage
1383
1443
session .run (
1384
1444
"coverage" ,
1385
1445
"html" ,
1386
1446
"-d" ,
1387
- str (COVERAGE_OUTPUT_DIR .joinpath ("html" ).relative_to (REPO_ROOT )),
1388
- "--include=salt/*,artifacts/salt/*,tests/*,pkg/tests/*" ,
1447
+ report_dir ,
1389
1448
"--show-contexts" ,
1449
+ * cmd_args ,
1390
1450
env = env ,
1391
1451
)
1392
1452
@@ -1406,7 +1466,7 @@ def _create_xml_coverage_reports(session):
1406
1466
"xml" ,
1407
1467
"-o" ,
1408
1468
str (COVERAGE_OUTPUT_DIR .joinpath ("tests.xml" ).relative_to (REPO_ROOT )),
1409
- "--omit=salt/*,artifacts/salt/* " ,
1469
+ "--omit=salt/*" ,
1410
1470
"--include=tests/*,pkg/tests/*" ,
1411
1471
env = env ,
1412
1472
)
@@ -1421,7 +1481,7 @@ def _create_xml_coverage_reports(session):
1421
1481
"-o" ,
1422
1482
str (COVERAGE_OUTPUT_DIR .joinpath ("salt.xml" ).relative_to (REPO_ROOT )),
1423
1483
"--omit=tests/*,pkg/tests/*" ,
1424
- "--include=salt/*,artifacts/salt/* " ,
1484
+ "--include=salt/*" ,
1425
1485
env = env ,
1426
1486
)
1427
1487
except CommandFailed :
0 commit comments