MCPcopy
hub / github.com/saltstack/salt / _define_testrun

Function _define_testrun

tools/ci.py:581–663  ·  view source on GitHub ↗
(ctx, changed_files, labels, full)

Source from the content-addressed store, hash-verified

579
580
581def _define_testrun(ctx, changed_files, labels, full):
582 if not changed_files.exists():
583 ctx.error(f"The '{changed_files}' file does not exist.")
584 ctx.error(
585 "FYI, the command 'tools process-changed-files <changed-files-path>' "
586 "needs to run prior to this one."
587 )
588 ctx.exit(1)
589 try:
590 changed_files_contents = json.loads(changed_files.read_text())
591 except Exception as exc:
592 ctx.error(f"Could not load the changed files from '{changed_files}': {exc}")
593 ctx.exit(1)
594
595 # Based on which files changed, or other things like PR labels we can
596 # decide what to run, or even if the full test run should be running on the
597 # pull request, etc...
598 changed_pkg_requirements_files: list[str] = []
599 changed_test_requirements_files: list[str] = []
600 if "pkg_requirements_files" in changed_files_contents:
601 changed_pkg_requirements_files = json.loads(
602 changed_files_contents["pkg_requirements_files"]
603 )
604 if "test_requirements_files" in changed_files_contents:
605 changed_test_requirements_files = json.loads(
606 changed_files_contents["test_requirements_files"]
607 )
608 if full:
609 ctx.info("Full test run chosen")
610 testrun = TestRun(type="full", skip_code_coverage=False)
611 elif changed_pkg_requirements_files or changed_test_requirements_files:
612 ctx.info(
613 "Full test run chosen because there was a change made "
614 "to the requirements files."
615 )
616 testrun = TestRun(type="full", skip_code_coverage=False)
617 elif "test:full" in labels:
618 ctx.info("Full test run chosen because the label `test:full` is set.\n")
619 testrun = TestRun(type="full", skip_code_coverage=False)
620 else:
621 testrun_changed_files_path = tools.utils.REPO_ROOT / "testrun-changed-files.txt"
622 testrun = TestRun(
623 type="changed",
624 skip_code_coverage=False,
625 from_filenames=str(
626 testrun_changed_files_path.relative_to(tools.utils.REPO_ROOT)
627 ),
628 )
629 ctx.info(f"Writing {testrun_changed_files_path.name} ...")
630 selected_changed_files = []
631 for fpath in json.loads(changed_files_contents["testrun_files"]):
632 if fpath.startswith(("tools/", "tasks/")):
633 continue
634 if fpath in ("noxfile.py",):
635 continue
636 if fpath == "tests/conftest.py":
637 # In this particular case, just run the full test suite
638 testrun["type"] = "full"

Callers 1

workflow_configFunction · 0.85

Calls 8

TestRunClass · 0.85
exitMethod · 0.80
existsMethod · 0.45
errorMethod · 0.45
loadsMethod · 0.45
read_textMethod · 0.45
infoMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected