From e68a98d54aad3d7a95f0a5eded242af725608deb Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Fri, 24 Oct 2025 17:26:46 +0000 Subject: [PATCH] Add convenient test runner script Provides shortcuts for: - Running all tests - Running specific test suites - Running with coverage - Running with fail-fast - Passing through to Django test runner --- run_tests.py | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 run_tests.py diff --git a/run_tests.py b/run_tests.py new file mode 100644 index 0000000..2157c54 --- /dev/null +++ b/run_tests.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +""" +Test runner script for vgui-cicd project. +Provides convenient shortcuts for running different test suites. +""" + +import sys +import os +from django.core.management import execute_from_command_line + + +def main(): + """Run tests based on command line arguments.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'VorgabenUI.settings') + + if len(sys.argv) > 1: + command = sys.argv[1] + + if command == 'all': + # Run all tests + execute_from_command_line(['manage.py', 'test', '--verbosity=2']) + + elif command == 'cache': + # Run only cache tests + execute_from_command_line(['manage.py', 'test', 'diagramm_proxy', '--verbosity=2']) + + elif command == 'render': + # Run only rendering tests + execute_from_command_line(['manage.py', 'test', 'abschnitte.tests', '--verbosity=2']) + + elif command == 'commands': + # Run only management command tests + execute_from_command_line(['manage.py', 'test', 'abschnitte.management.commands', '--verbosity=2']) + + elif command == 'coverage': + # Run tests with coverage + try: + import coverage + cov = coverage.Coverage(source=['.']) + cov.start() + + execute_from_command_line(['manage.py', 'test', '--verbosity=2']) + + cov.stop() + cov.save() + + print('\n' + '='*70) + print('COVERAGE REPORT') + print('='*70) + cov.report() + + print('\nHTML coverage report generated in htmlcov/') + cov.html_report() + + except ImportError: + print('ERROR: coverage.py not installed.') + print('Install with: pip install coverage') + sys.exit(1) + + elif command == 'fast': + # Run tests with failfast + execute_from_command_line(['manage.py', 'test', '--failfast', '--verbosity=2']) + + elif command == 'help': + print_help() + + else: + # Pass through to Django test runner + execute_from_command_line(['manage.py', 'test'] + sys.argv[1:]) + + else: + print_help() + + +def print_help(): + """Print help message.""" + help_text = """ +Usage: python run_tests.py [command] + +Commands: + all Run all tests + cache Run diagram cache tests only + render Run rendering tests only + commands Run management command tests only + coverage Run tests with coverage report + fast Run tests with fail-fast option + help Show this help message + +Advanced: + You can also pass standard Django test arguments: + python run_tests.py + python run_tests.py + python run_tests.py + +Examples: + python run_tests.py all + python run_tests.py cache + python run_tests.py coverage + python run_tests.py diagramm_proxy.test_diagram_cache.DiagramCacheTestCase + python run_tests.py abschnitte.tests.RenderTextabschnitteTestCase.test_render_diagram_success + +For more options, see Documentation/TESTING.md +""" + print(help_text) + + +if __name__ == '__main__': + main()