feat: fix test collection and add collection stats display
- Fix collect_tests to use JSON report parsing (was returning 0 tests) - Add Test Collection panel to testing dashboard showing total tests, unit/integration/performance breakdown, and file count - Reorganize sidebar: create Platform Health section with Testing Hub, Code Quality, and Background Tasks - Keep Developer Tools for Components and Icons only - Platform Monitoring now contains Import Jobs and Application Logs 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -375,6 +375,12 @@ class TestRunnerService:
|
||||
|
||||
# Collection stats
|
||||
"total_test_files": collection.total_files if collection else 0,
|
||||
"collected_tests": collection.total_tests if collection else 0,
|
||||
"unit_tests": collection.unit_tests if collection else 0,
|
||||
"integration_tests": collection.integration_tests if collection else 0,
|
||||
"performance_tests": collection.performance_tests if collection else 0,
|
||||
"system_tests": collection.system_tests if collection else 0,
|
||||
"last_collected": collection.collected_at.isoformat() if collection else None,
|
||||
|
||||
# Trend data
|
||||
"trend": [
|
||||
@@ -410,47 +416,70 @@ class TestRunnerService:
|
||||
)
|
||||
|
||||
try:
|
||||
# Run pytest --collect-only
|
||||
# Run pytest --collect-only with JSON report
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
||||
json_report_path = f.name
|
||||
|
||||
result = subprocess.run(
|
||||
["python", "-m", "pytest", "--collect-only", "-q", "tests"],
|
||||
[
|
||||
"python", "-m", "pytest",
|
||||
"--collect-only",
|
||||
"--json-report",
|
||||
f"--json-report-file={json_report_path}",
|
||||
"tests"
|
||||
],
|
||||
cwd=str(self.project_root),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=60,
|
||||
timeout=120,
|
||||
)
|
||||
|
||||
# Parse output
|
||||
lines = result.stdout.strip().split('\n')
|
||||
test_files = {}
|
||||
# Parse JSON report
|
||||
json_path = Path(json_report_path)
|
||||
if json_path.exists():
|
||||
with open(json_path) as f:
|
||||
report = json.load(f)
|
||||
|
||||
for line in lines:
|
||||
if "::" in line:
|
||||
file_path = line.split("::")[0]
|
||||
if file_path not in test_files:
|
||||
test_files[file_path] = 0
|
||||
test_files[file_path] += 1
|
||||
# Get total from summary
|
||||
collection.total_tests = report.get("summary", {}).get("collected", 0)
|
||||
|
||||
# Count by category
|
||||
for file_path, count in test_files.items():
|
||||
collection.total_tests += count
|
||||
collection.total_files += 1
|
||||
# Parse collectors to get test files and counts
|
||||
test_files = {}
|
||||
for collector in report.get("collectors", []):
|
||||
for item in collector.get("result", []):
|
||||
if item.get("type") == "Function":
|
||||
node_id = item.get("nodeid", "")
|
||||
if "::" in node_id:
|
||||
file_path = node_id.split("::")[0]
|
||||
if file_path not in test_files:
|
||||
test_files[file_path] = 0
|
||||
test_files[file_path] += 1
|
||||
|
||||
if "unit" in file_path:
|
||||
collection.unit_tests += count
|
||||
elif "integration" in file_path:
|
||||
collection.integration_tests += count
|
||||
elif "performance" in file_path:
|
||||
collection.performance_tests += count
|
||||
elif "system" in file_path:
|
||||
collection.system_tests += count
|
||||
# Count files and categorize
|
||||
for file_path, count in test_files.items():
|
||||
collection.total_files += 1
|
||||
|
||||
collection.test_files = [
|
||||
{"file": f, "count": c}
|
||||
for f, c in sorted(test_files.items(), key=lambda x: -x[1])
|
||||
]
|
||||
if "/unit/" in file_path or file_path.startswith("tests/unit"):
|
||||
collection.unit_tests += count
|
||||
elif "/integration/" in file_path or file_path.startswith("tests/integration"):
|
||||
collection.integration_tests += count
|
||||
elif "/performance/" in file_path or file_path.startswith("tests/performance"):
|
||||
collection.performance_tests += count
|
||||
elif "/system/" in file_path or file_path.startswith("tests/system"):
|
||||
collection.system_tests += count
|
||||
|
||||
collection.test_files = [
|
||||
{"file": f, "count": c}
|
||||
for f, c in sorted(test_files.items(), key=lambda x: -x[1])
|
||||
]
|
||||
|
||||
# Cleanup
|
||||
json_path.unlink(missing_ok=True)
|
||||
|
||||
logger.info(f"Collected {collection.total_tests} tests from {collection.total_files} files")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error collecting tests: {e}")
|
||||
logger.error(f"Error collecting tests: {e}", exc_info=True)
|
||||
|
||||
db.add(collection)
|
||||
return collection
|
||||
|
||||
Reference in New Issue
Block a user