[WIP] Add tests and coverage
This commit is contained in:
Executable
+78
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Clean pytest-based coverage runner for container environment.
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_pytest_with_coverage():
|
||||
"""Run pytest with coverage analysis."""
|
||||
print("🧪 Running pytest with coverage...")
|
||||
|
||||
# Ensure we're in the right directory
|
||||
if Path('/src').exists():
|
||||
os.chdir('/src')
|
||||
else:
|
||||
os.chdir(Path(__file__).parent.parent)
|
||||
|
||||
# Clean previous coverage data
|
||||
subprocess.run(['coverage', 'erase'], capture_output=True)
|
||||
|
||||
# Run pytest with coverage
|
||||
cmd = [
|
||||
'python3', '-m', 'pytest',
|
||||
'tests/test_pytest_suite.py',
|
||||
'--cov=.',
|
||||
'--cov-report=term-missing',
|
||||
'--cov-report=html:coverage_html_report',
|
||||
'--cov-report=xml:coverage.xml',
|
||||
'--cov-config=.coveragerc',
|
||||
'-v'
|
||||
]
|
||||
|
||||
print(f"Running: {' '.join(cmd)}")
|
||||
result = subprocess.run(cmd)
|
||||
|
||||
if result.returncode == 0:
|
||||
print("\n✅ Pytest coverage completed successfully!")
|
||||
|
||||
# Extract coverage percentage
|
||||
try:
|
||||
coverage_result = subprocess.run(
|
||||
['coverage', 'report', '--format=total'],
|
||||
capture_output=True, text=True
|
||||
)
|
||||
if coverage_result.returncode == 0:
|
||||
coverage_pct = float(coverage_result.stdout.strip())
|
||||
print(f"🎯 Total Coverage: {coverage_pct:.2f}%")
|
||||
|
||||
if coverage_pct >= 80:
|
||||
print("✅ Coverage target met (≥80%)")
|
||||
return True
|
||||
else:
|
||||
print("⚠️ Coverage below target (≥80%)")
|
||||
except (ValueError, subprocess.SubprocessError):
|
||||
print("⚠️ Could not extract coverage percentage")
|
||||
|
||||
return True
|
||||
else:
|
||||
print("❌ Pytest coverage failed!")
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
print("=" * 60)
|
||||
print("🔬 Gallery Generator - Pytest Coverage Testing")
|
||||
print("=" * 60)
|
||||
|
||||
success = run_pytest_with_coverage()
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user