(
session,
combine=True,
cli_report=True,
html_report=False,
xml_report=False,
json_report=False,
)
| 455 | |
| 456 | |
| 457 | def _report_coverage( |
| 458 | session, |
| 459 | combine=True, |
| 460 | cli_report=True, |
| 461 | html_report=False, |
| 462 | xml_report=False, |
| 463 | json_report=False, |
| 464 | ): |
| 465 | _install_coverage_requirement(session) |
| 466 | |
| 467 | if not any([combine, cli_report, html_report, xml_report, json_report]): |
| 468 | session.error( |
| 469 | "At least one of combine, cli_report, html_report, xml_report, json_report needs to be True" |
| 470 | ) |
| 471 | |
| 472 | env = { |
| 473 | # The full path to the .coverage data file. Makes sure we always write |
| 474 | # them to the same directory |
| 475 | "COVERAGE_FILE": COVERAGE_FILE, |
| 476 | } |
| 477 | |
| 478 | report_section = None |
| 479 | if session.posargs: |
| 480 | report_section = session.posargs.pop(0) |
| 481 | if report_section not in ("salt", "tests"): |
| 482 | session.error( |
| 483 | f"The report section can only be one of 'salt', 'tests', not: {report_section}" |
| 484 | ) |
| 485 | if session.posargs: |
| 486 | session.error( |
| 487 | "Only one argument can be passed to the session, which is optional " |
| 488 | "and is one of 'salt', 'tests'." |
| 489 | ) |
| 490 | |
| 491 | if combine is True: |
| 492 | coverage_db_files = glob.glob(f"{COVERAGE_FILE}.*") |
| 493 | if coverage_db_files: |
| 494 | with contextlib.suppress(CommandFailed): |
| 495 | # Sometimes some of the coverage files are corrupt which would trigger a CommandFailed |
| 496 | # exception |
| 497 | session.run("coverage", "combine", env=env) |
| 498 | elif os.path.exists(COVERAGE_FILE): |
| 499 | session_warn(session, "Coverage files already combined.") |
| 500 | |
| 501 | if os.path.exists(COVERAGE_FILE) and not IS_WINDOWS: |
| 502 | # Some coverage files might have come from a windows machine, fix paths |
| 503 | with sqlite3.connect(COVERAGE_FILE) as db: |
| 504 | res = db.execute(r"SELECT * FROM file WHERE path LIKE '%salt\%'") |
| 505 | if res.fetchone(): |
| 506 | session_warn( |
| 507 | session, |
| 508 | "Replacing backwards slashes with forward slashes on file " |
| 509 | "paths in the coverage database", |
| 510 | ) |
| 511 | db.execute( |
| 512 | r"UPDATE OR IGNORE file SET path=replace(path, '\', '/');" |
| 513 | ) |
| 514 |
no test coverage detected