mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-15 12:38:03 +00:00
Fix coverage measurement in CI
- Replace subprocess call with direct Django test runner invocation - This allows coverage tool to properly track test execution - Use django.setup() and get_runner() to run tests directly - Coverage should now show proper test coverage instead of 1%
This commit is contained in:
@@ -1,34 +1,46 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Run tests with OpenTelemetry enabled and coverage measurement.
|
||||
This script is designed to be used with 'coverage run' command.
|
||||
"""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import django
|
||||
from django.conf import settings
|
||||
from django.test.utils import get_runner
|
||||
|
||||
|
||||
def main():
|
||||
# Enable OpenTelemetry
|
||||
os.environ['ENABLE_OPENTELEMETRY'] = 'true'
|
||||
os.environ['OTEL_ENABLED'] = 'true'
|
||||
os.environ['OTEL_SERVICE_NAME'] = 'ivatar-test'
|
||||
os.environ['OTEL_ENVIRONMENT'] = 'test'
|
||||
|
||||
os.environ["ENABLE_OPENTELEMETRY"] = "true"
|
||||
os.environ["OTEL_ENABLED"] = "true"
|
||||
os.environ["OTEL_SERVICE_NAME"] = "ivatar-test"
|
||||
os.environ["OTEL_ENVIRONMENT"] = "test"
|
||||
|
||||
print("Running tests with OpenTelemetry enabled...")
|
||||
print("==========================================")
|
||||
|
||||
# Run Django tests (Django will auto-discover all tests)
|
||||
cmd = ['python3', 'manage.py', 'test', '-v2']
|
||||
|
||||
try:
|
||||
result = subprocess.run(cmd, check=True)
|
||||
|
||||
# Setup Django
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ivatar.settings")
|
||||
django.setup()
|
||||
|
||||
# Get Django test runner
|
||||
TestRunner = get_runner(settings)
|
||||
test_runner = TestRunner()
|
||||
|
||||
# Run tests
|
||||
failures = test_runner.run_tests([])
|
||||
|
||||
if failures:
|
||||
print(f"Tests failed with {failures} failures")
|
||||
return 1
|
||||
else:
|
||||
print("")
|
||||
print("Tests completed successfully (OpenTelemetry enabled)")
|
||||
return result.returncode
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Tests failed with exit code {e.returncode}")
|
||||
return e.returncode
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user