Coverage for scripts/run_tests_with_coverage.py: 93%
27 statements
« prev ^ index » next coverage.py v7.14.2, created at 2026-06-21 23:07 +0000
« prev ^ index » next coverage.py v7.14.2, created at 2026-06-21 23:07 +0000
1#!/usr/bin/env python3
2"""
3Run tests with OpenTelemetry instrumentation and export enabled, plus coverage measurement.
4This script is designed to be used with 'coverage run' command.
5"""
7import os
8import sys
9import django
10from django.conf import settings
11from django.test.utils import get_runner
14def main():
15 # Enable OpenTelemetry instrumentation and export (if not already set)
16 os.environ.setdefault("OTEL_EXPORT_ENABLED", "true")
17 os.environ["OTEL_SERVICE_NAME"] = "ivatar-test"
18 os.environ["OTEL_ENVIRONMENT"] = "test"
20 print("Running tests with OpenTelemetry instrumentation and export enabled...")
21 print("====================================================================")
23 # Add current directory to Python path
24 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
26 # Setup Django
27 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ivatar.settings")
28 django.setup()
30 # Disable async access count updates to prevent background threads causing DB locks during teardown
31 from django.conf import settings
32 settings.ASYNC_ACCESS_COUNT = False
34 # Get Django test runner
35 TestRunner = get_runner(settings)
36 test_runner = TestRunner()
38 # Run tests
39 failures = test_runner.run_tests([])
41 if failures:
42 print(f"Tests failed with {failures} failures")
43 return 1
44 else:
45 print("")
46 print(
47 "Tests completed successfully (OpenTelemetry instrumentation and export enabled)"
48 )
49 return 0
52if __name__ == "__main__":
53 sys.exit(main())