Coverage for scripts/run_tests_with_coverage.py: 92%

25 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-24 23:06 +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""" 

6 

7import os 

8import sys 

9import django 

10from django.conf import settings 

11from django.test.utils import get_runner 

12 

13 

14def main(): 

15 # Enable OpenTelemetry instrumentation and export 

16 os.environ["OTEL_EXPORT_ENABLED"] = "true" 

17 os.environ["OTEL_SERVICE_NAME"] = "ivatar-test" 

18 os.environ["OTEL_ENVIRONMENT"] = "test" 

19 

20 print("Running tests with OpenTelemetry instrumentation and export enabled...") 

21 print("====================================================================") 

22 

23 # Add current directory to Python path 

24 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 

25 

26 # Setup Django 

27 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ivatar.settings") 

28 django.setup() 

29 

30 # Get Django test runner 

31 TestRunner = get_runner(settings) 

32 test_runner = TestRunner() 

33 

34 # Run tests 

35 failures = test_runner.run_tests([]) 

36 

37 if failures: 

38 print(f"Tests failed with {failures} failures") 

39 return 1 

40 else: 

41 print("") 

42 print( 

43 "Tests completed successfully (OpenTelemetry instrumentation and export enabled)" 

44 ) 

45 return 0 

46 

47 

48if __name__ == "__main__": 

49 sys.exit(main())