-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests_clean.py
More file actions
executable file
·92 lines (72 loc) · 2.57 KB
/
run_tests_clean.py
File metadata and controls
executable file
·92 lines (72 loc) · 2.57 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
91
92
#!/usr/bin/env python3
"""
Test runner script that ensures all tests use temporary directories and clean up properly.
This script runs the test suite and ensures that no temporary files are left behind.
"""
import os
import sys
import tempfile
import shutil
import subprocess
from pathlib import Path
import argparse
def cleanup_temp_files():
"""Clean up any temporary files that might have been left behind."""
temp_dir = Path(tempfile.gettempdir())
# Look for test-related temporary files
patterns = [
"graphflow_test_*",
"tmp*",
"test_*",
"pytest_*"
]
cleaned_count = 0
for pattern in patterns:
for temp_file in temp_dir.glob(pattern):
try:
if temp_file.is_dir():
shutil.rmtree(temp_file, ignore_errors=True)
cleaned_count += 1
else:
temp_file.unlink(missing_ok=True)
cleaned_count += 1
except (OSError, PermissionError):
# Ignore errors - some files might be in use
pass
if cleaned_count > 0:
print(f"Cleaned up {cleaned_count} temporary files/directories")
def run_tests(test_args=None):
"""Run the test suite with proper cleanup."""
if test_args is None:
test_args = []
# Clean up before running tests
print("Cleaning up any existing temporary files...")
cleanup_temp_files()
# Run the tests
cmd = [sys.executable, "-m", "pytest"] + test_args
print(f"Running tests with command: {' '.join(cmd)}")
try:
result = subprocess.run(cmd, cwd=Path(__file__).parent)
return result.returncode
finally:
# Clean up after running tests
print("Cleaning up temporary files after tests...")
cleanup_temp_files()
def main():
"""Main entry point."""
parser = argparse.ArgumentParser(description="Run GraphFlow tests with proper cleanup")
parser.add_argument("test_args", nargs="*", help="Additional arguments to pass to pytest")
parser.add_argument("--clean-only", action="store_true", help="Only clean up temporary files")
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose output")
args = parser.parse_args()
if args.clean_only:
cleanup_temp_files()
return 0
# Add verbose flag if requested
test_args = args.test_args
if args.verbose:
test_args = ["-v"] + test_args
# Run tests
return run_tests(test_args)
if __name__ == "__main__":
sys.exit(main())