-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.py
More file actions
90 lines (73 loc) · 2.3 KB
/
run_tests.py
File metadata and controls
90 lines (73 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""Test runner for BlenderCode — handles both pure pytest and Blender-backed tests."""
import subprocess
import sys
from pathlib import Path
def run_pure_tests():
"""Run pure Python tests that don't need Blender."""
print("=" * 60)
print("Running pure Python tests...")
print("=" * 60)
result = subprocess.run(
[
sys.executable, "-m", "pytest",
"tests/",
"-v",
"--ignore=tests/tools",
"--ignore=tests/test_ui.py",
"-k", "not test_undo_stack and not test_context_builder",
],
cwd=Path(__file__).parent,
)
return result.returncode
def run_blender_tests():
"""Run tests that require Blender's bpy module."""
blender_exe = _find_blender()
if blender_exe is None:
print("\nBlender not found — skipping Blender-backed tests")
return 0
print("\n" + "=" * 60)
print(f"Running Blender-backed tests with {blender_exe}...")
print("=" * 60)
result = subprocess.run(
[
blender_exe, "--background", "--python",
"-m", "pytest",
"tests/", "-v",
],
cwd=Path(__file__).parent,
)
return result.returncode
def _find_blender() -> str | None:
"""Try to find Blender executable."""
import shutil
for name in ["blender", "blender.exe", "blender-launcher.exe"]:
path = shutil.which(name)
if path:
return path
# Check common Windows paths
import platform
if platform.system() == "Windows":
program_files = Path("C:/Program Files")
for d in program_files.glob("Blender Foundation/Blender *"):
exe = d / "blender.exe"
if exe.exists():
return str(exe)
# Check Steam
steam = Path("C:/Program Files (x86)/Steam/steamapps/common/Blender")
if (steam / "blender.exe").exists():
return str(steam / "blender.exe")
return None
def main():
code = run_pure_tests()
blender_code = run_blender_tests()
if code != 0:
print("\nPure Python tests FAILED")
sys.exit(1)
if blender_code != 0:
print("\nBlender-backed tests FAILED")
sys.exit(1)
print("\nAll tests passed!")
sys.exit(0)
if __name__ == "__main__":
main()