Get accurate counts of unit tests, examples, and Python tests. Returns: TestCounts with unit_test_count, example_count, and python_test_count.
()
| 81 | |
| 82 | |
| 83 | def get_test_counts() -> TestCounts: |
| 84 | """ |
| 85 | Get accurate counts of unit tests, examples, and Python tests. |
| 86 | |
| 87 | Returns: |
| 88 | TestCounts with unit_test_count, example_count, and python_test_count. |
| 89 | """ |
| 90 | try: |
| 91 | from pathlib import Path |
| 92 | |
| 93 | from ci.util.smart_selector import discover_all_tests |
| 94 | |
| 95 | # Get unit tests and examples |
| 96 | unit_tests, examples = discover_all_tests(Path.cwd()) |
| 97 | unit_count = len(unit_tests) |
| 98 | example_count = len(examples) |
| 99 | |
| 100 | # Count Python tests by running pytest --collect-only |
| 101 | python_count = 0 |
| 102 | try: |
| 103 | result = RunningProcess.run( |
| 104 | ["uv", "run", "pytest", "--collect-only", "-q", "ci/tests"], |
| 105 | cwd=None, |
| 106 | check=False, |
| 107 | timeout=10, |
| 108 | ) |
| 109 | if result.returncode == 0: |
| 110 | # Parse output to count tests |
| 111 | # pytest --collect-only -q outputs lines like "test_foo.py::test_bar" |
| 112 | lines = result.stdout.strip().split("\n") |
| 113 | python_count = sum(1 for line in lines if "::" in line) |
| 114 | except KeyboardInterrupt as ki: |
| 115 | handle_keyboard_interrupt(ki) |
| 116 | raise |
| 117 | except (subprocess.SubprocessError, RuntimeError): |
| 118 | # If counting fails, use 0 as fallback |
| 119 | python_count = 0 |
| 120 | |
| 121 | return TestCounts( |
| 122 | unit_test_count=unit_count, |
| 123 | example_count=example_count, |
| 124 | python_test_count=python_count, |
| 125 | ) |
| 126 | |
| 127 | except KeyboardInterrupt as ki: |
| 128 | handle_keyboard_interrupt(ki) |
| 129 | raise |
| 130 | except Exception: |
| 131 | # If discovery fails, return zeros |
| 132 | return TestCounts(unit_test_count=0, example_count=0, python_test_count=0) |
| 133 | |
| 134 | |
| 135 | # Pre-compiled patterns for detecting real error lines (not compiler flags). |
no test coverage detected