Skip to content

Commit 83a032e

Browse files
authored
chore: improve scripts/run-tests --venv handling (#15188)
## Description If you run `scripts/run-tests --venv <hash>` it might still expect you to provide changed files or look at git diff for changed files to determine which venvs are possible to run. With this change, if `--venv <hash>` is provided we run those hashes directly now instead. ## Testing <!-- Describe your testing strategy or note what tests are included --> ## Risks <!-- Note any risks associated with this change, or "None" if no risks --> ## Additional Notes <!-- Any other information that would be helpful for reviewers -->
1 parent 35307d9 commit 83a032e

File tree

1 file changed

+73
-12
lines changed

1 file changed

+73
-12
lines changed

scripts/run-tests

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,45 @@ class TestRunner:
248248
print(f"Warning: Failed to get riot venvs for pattern '{pattern}': {e}")
249249
return []
250250

251+
def get_all_riot_venvs(self) -> List[RiotVenv]:
252+
"""Get all available riot venvs without pattern filtering."""
253+
try:
254+
venvs = []
255+
256+
# Get all venv instances without pattern filtering
257+
for n, inst in enumerate(riotfile.venv.instances()):
258+
if not inst.name:
259+
continue
260+
261+
# Extract package information from the instance
262+
packages_info = ""
263+
if hasattr(inst, 'pkgs') and inst.pkgs:
264+
all_packages = [f"{pkg}: {version}" for pkg, version in inst.pkgs.items()]
265+
packages_info = ", ".join(all_packages) if all_packages else "standard packages"
266+
267+
# Extract command from the instance
268+
command = ""
269+
if hasattr(inst, 'cmd'):
270+
command = str(inst.cmd)
271+
elif hasattr(inst, 'command'):
272+
command = str(inst.command)
273+
274+
venvs.append(RiotVenv(
275+
number=n,
276+
hash=inst.short_hash if hasattr(inst, 'short_hash') else f"hash{n}",
277+
name=inst.name,
278+
python_version=str(inst.py._hint) if hasattr(inst, 'py') and hasattr(inst.py, '_hint') else "3.10",
279+
packages=packages_info,
280+
suite_name="",
281+
command=command
282+
))
283+
284+
return venvs
285+
286+
except Exception as e:
287+
print(f"Warning: Failed to get all riot venvs: {e}")
288+
return []
289+
251290
def start_services(self, services: Set[str]) -> bool:
252291
"""Start required Docker services."""
253292
if not services:
@@ -539,6 +578,25 @@ class TestRunner:
539578

540579
return selected_venvs
541580

581+
def get_venvs_by_hash_direct(self, venv_hashes: List[str]) -> List[RiotVenv]:
582+
"""Get specific venvs by their hashes from all available venvs.
583+
584+
This method doesn't require suite information and is used when --venv is provided directly.
585+
"""
586+
all_venvs = self.get_all_riot_venvs()
587+
venv_hashes_set = set(venv_hashes)
588+
matched_venvs = [venv for venv in all_venvs if venv.hash in venv_hashes_set]
589+
590+
if not matched_venvs:
591+
return []
592+
593+
# Print info about found venvs
594+
print(f"📌 Found {len(matched_venvs)} venv(s):")
595+
for venv in matched_venvs:
596+
print(f" • {venv.hash}: {venv.name} ({venv.display_name})")
597+
598+
return matched_venvs
599+
542600

543601
def main():
544602
parser = argparse.ArgumentParser(
@@ -612,7 +670,19 @@ Examples:
612670

613671
runner = TestRunner()
614672

615-
# Determine which files to check
673+
# Special handling for --venv: skip all file discovery and suite matching
674+
if args.venv:
675+
print("🎯 Using directly specified venvs (skipping file/suite analysis)")
676+
selected_venvs = runner.get_venvs_by_hash_direct(args.venv)
677+
if not selected_venvs:
678+
print(f"❌ No venvs found matching hashes: {', '.join(args.venv)}")
679+
return 1
680+
# When using --venv directly, skip service management
681+
print(f"⚠️ Skipping service management (run manually if needed)")
682+
success = runner.run_tests(selected_venvs, {}, riot_args=riot_args, dry_run=args.dry_run)
683+
return 0 if success else 1
684+
685+
# Normal flow: determine which files to check
616686
if args.files:
617687
# Use explicitly provided files
618688
files = set(args.files)
@@ -646,17 +716,8 @@ Examples:
646716
runner.output_suites_json(matching_suites)
647717
return 0
648718

649-
# Determine venv selection method
650-
if args.venv:
651-
# Use provided venvs (no interactive prompts)
652-
selected_venvs = runner.select_venvs_by_hash(matching_suites, args.venv)
653-
if not selected_venvs:
654-
print(f"❌ No venvs found matching hashes: {', '.join(args.venv)}")
655-
return 1
656-
print(f"📌 Selected {len(selected_venvs)} venv(s) from provided hashes")
657-
else:
658-
# Interactive venv selection
659-
selected_venvs = runner.interactive_venv_selection(matching_suites)
719+
# Interactive venv selection
720+
selected_venvs = runner.interactive_venv_selection(matching_suites)
660721

661722
# Execute tests
662723
success = runner.run_tests(selected_venvs, matching_suites, riot_args=riot_args, dry_run=args.dry_run)

0 commit comments

Comments
 (0)