Files
ivatar/scripts/run_tests_with_coverage.py
Oliver Falk b95bf287bf Fix Python path issue in coverage script
- Add current directory to Python path before calling django.setup()
- This fixes ModuleNotFoundError: No module named 'ivatar'
- The script now properly finds the ivatar module when running tests
- Coverage should now work correctly with Django test runner
2025-10-16 19:59:25 +02:00

50 lines
1.3 KiB
Python
Executable File

#!/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 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"
print("Running tests with OpenTelemetry enabled...")
print("==========================================")
# Add current directory to Python path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# 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 0
if __name__ == "__main__":
sys.exit(main())