|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Test runner for scalar-django-ninja integration. |
| 4 | +This script runs all tests and provides a summary. |
| 5 | +""" |
| 6 | + |
| 7 | +import subprocess |
| 8 | +import sys |
| 9 | +import os |
| 10 | +from pathlib import Path |
| 11 | + |
| 12 | + |
| 13 | +def run_tests(): |
| 14 | + """Run all tests for the scalar-django-ninja integration""" |
| 15 | + |
| 16 | + # Get the directory where this script is located |
| 17 | + script_dir = Path(__file__).parent |
| 18 | + os.chdir(script_dir) |
| 19 | + |
| 20 | + print("🧪 Running Scalar Django Ninja Integration Tests") |
| 21 | + print("=" * 50) |
| 22 | + |
| 23 | + # Check if pytest is available |
| 24 | + try: |
| 25 | + import pytest |
| 26 | + except ImportError: |
| 27 | + print("❌ pytest is not installed. Installing test dependencies...") |
| 28 | + subprocess.run( |
| 29 | + [sys.executable, "-m", "pip", "install", "-r", "tests/requirements.txt"], |
| 30 | + check=True, |
| 31 | + ) |
| 32 | + |
| 33 | + # Run the tests |
| 34 | + print("📋 Running unit tests...") |
| 35 | + result = subprocess.run( |
| 36 | + [sys.executable, "-m", "pytest", "tests/", "-v", "--tb=short", "--color=yes"] |
| 37 | + ) |
| 38 | + |
| 39 | + if result.returncode == 0: |
| 40 | + print("\n✅ All tests passed!") |
| 41 | + else: |
| 42 | + print("\n❌ Some tests failed!") |
| 43 | + sys.exit(1) |
| 44 | + |
| 45 | + |
| 46 | +def run_specific_test(test_file=None, test_function=None): |
| 47 | + """Run a specific test file or function""" |
| 48 | + |
| 49 | + script_dir = Path(__file__).parent |
| 50 | + os.chdir(script_dir) |
| 51 | + |
| 52 | + cmd = [sys.executable, "-m", "pytest", "-v", "--tb=short", "--color=yes"] |
| 53 | + |
| 54 | + if test_file: |
| 55 | + cmd.append(f"tests/{test_file}") |
| 56 | + |
| 57 | + if test_function: |
| 58 | + cmd.append(f"-k {test_function}") |
| 59 | + |
| 60 | + subprocess.run(cmd) |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + if len(sys.argv) > 1: |
| 65 | + if sys.argv[1] == "--help" or sys.argv[1] == "-h": |
| 66 | + print("Usage:") |
| 67 | + print(" python run_tests.py # Run all tests") |
| 68 | + print(" python run_tests.py test_file.py # Run specific test file") |
| 69 | + print( |
| 70 | + " python run_tests.py test_file.py func # Run specific test function" |
| 71 | + ) |
| 72 | + elif len(sys.argv) == 2: |
| 73 | + run_specific_test(sys.argv[1]) |
| 74 | + elif len(sys.argv) == 3: |
| 75 | + run_specific_test(sys.argv[1], sys.argv[2]) |
| 76 | + else: |
| 77 | + run_tests() |
0 commit comments